-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assert hook should evaluate recursively #73
Comments
This is intentional. It seems more useful to me in for example:
to get
rather than
As you note yourself, it's easily worked around by making it a variable. Alternative solutions would be to limit non-evaluation to builtins, or evaluate and show in "steps", something like
Also I suppose it could evaluate calls that aren't taking any arguments ... What do you think is the best solution (or combination thereof) here? |
I would say that the best solution is to evaluate and show it in steps, but (sometimes) it can add too much noise and unnecessary information, like in py.test http://pytest.org/assert.html#assert-with-the-assert-statement. Let me explain better the "scenario", so you can understand better the problem: I was testing the correct behaviour of a function, given an input, I want that output:
In this scenario the Assert wrapping only the left member was perfect, thanks to that for example I discovered that MinScale.step_down was returning shifted results (and let me quickly correct them). Using assert it was giving me:
That by the way is equivalent to this expression:
So in this case the problem was to find a way to distinguish between this two cases:
|
Do you think it sufficient to evaluate in only two steps, and not evaluate nested calls recursively? That'd be less noisy. Complicated nesting in a one-liner doesn't seem very Pythonic anyway. Example:
Show on failure:
Skipped:
Hm, writing this example I realise it might be useful to recurse anyway, and examples such as "not False" should perhaps just be excluded. The most useful output for the above example would be:
Thoughts? |
Analyzing the tests in attest sourcecode and some of my old projects. Most tests fall in two main categories, comparisons and assertive functions (there are also assertRaises but usually they are simple). Example comparisons:
Example assertive: I think that comparisons usually need both the last call (for example len([1,2,3])) and the return value. As you said there aren't so much calls in a one-liner so adding all the nested calls won't result in much noise and covers more cases. assertive functions ('not' and everything that isn't a comparison operator) don't need the return call but need the steps. A solution can be to distinguish between this two classes (actually just make the comparison special case): comparisons: ==, !=, <> etc.. http://docs.python.org/reference/expressions.html#comparisons all the others:
They need just the calls. |
Not all predicates necessarily return |
Also,
It scares me to "special-case" things too much. If it has real practical value and is consistent without exceptional cases I suppose it's fine but care should be taken here to not make too many assumptions, and to keep it simple. |
I don't think that the return value of the predicates is useful (most of the time), for example:
In this assertion I may be interested in which the return value of something is, but more commonly one would write the (imho more correct) following expression:
The special case scares me also, it's very easy in fact to fall in inconsistencies of some sort. What I was thinking is like, if the last expression is an 'or_expr' (don't know if it is an 'or_expr', expand all the calls except the last:
if the last expression is a 'comparison', expand all the calls (I'm inventing):
since:
It should work also with multiple comparisons:
But there should be problem also with Don't know how it would behave with:
Because the first is a "not" + not_test and don't know what the second is. Maybe the answer to what is more general and mantainablle is contained in the way that python parse code, aka to find a common breakpoint for all the cases or the most general cases (comparison, not_test, or_expr ?). |
I'm testing the last revisions, using the assert_hook stuff. Maybe it's a bit premature to post issues about this feature, but I've written a little test to show the problematic behaviour.
The text was updated successfully, but these errors were encountered: