-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[RFC/WIP] Display line numbers in short test summary #5242
Conversation
One idea would be for pytest to accept Related: #3282 |
Also having the crash location explicitly appended might be good:
But for the first case I think it is better to have the location / line from the test itself - so I've changed it to do that now. |
if isinstance(testloc.path, six.string_types): | ||
testloc_path = py.path.local(testloc.path) | ||
else: | ||
testloc_path = testloc.path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I've seen this to be necessary when testing, but only one branch is covered here.
if rel_testloc_path == path: | ||
return "%s (line %d)" % (nodeid, testloc.lineno) | ||
|
||
return "%s (%s:%d)" % (nodeid, rel_testloc_path, testloc.lineno) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense like this?
Is there a better API (to get to the entry in the test)?
except AttributeError: | ||
return nodeid | ||
|
||
if isinstance(testloc.path, six.string_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do just this:
testloc_path = py.path.local(testloc.path)
If testloc.path
is already a py.path.local
instance, then it should be a noop (or very cheap).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this was more to see if it is needed after all (via coverage).
IIRC I've seen some inconsistency when testing, but only one case is used IIRC^2.
if rel_testloc_path == path: | ||
return "%s (line %d)" % (nodeid, testloc.lineno) | ||
|
||
return "%s (%s:%d)" % (nodeid, rel_testloc_path, testloc.lineno) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which situation does this fall into? Won't this generate very long summary lines? I fear as it is the message already takes quite all the terminal space and most of the times it gets trimmed anyway, adding this information to the summary line will make it even less useful, as more of exception message will be trimmed.
How do you feel if we include this information only when -v
is passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the last case?
Ok with verbose > 0 here.
Adding only " (line XX)" is useful.
It is probably not hit anyway I would imagine (have not checked).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About -v
, I meant if we only added line numbers of -v
is passed. In retrospect this could also be the case for the message summary as well I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think those are very useful to have by default and only add like ~10 extra chars.
Done in my fork: blueyed@c947224 @asfaltboy (since you +1'd): feel free to pick it up from there. I've gone with a slightly different format there. |
Fixes #5241.
TODO: