Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented May 10, 2019

Fixes #5241.

TODO:

  • test
  • changelog

@blueyed blueyed changed the title Display line numbers in short test summary [WIP] Display line numbers in short test summary May 10, 2019
@blueyed
Copy link
Contributor Author

blueyed commented May 11, 2019

One idea would be for pytest to accept fname:lnum::test as an argument, but ignore the :lnum part therein.

Related: #3282

@blueyed
Copy link
Contributor Author

blueyed commented May 11, 2019

Also having the crash location explicitly appended might be good:

FAILED testing/test_pdb.py::TestPDB::test_pdb_interaction_capturing_simple (.venv/lib/python3.7/site-packages/pexpect/expect.py:82) - pexpect.exceptions.TIMEOUT: Timeout e...

FAILED testing/test_pdb.py::TestDebuggingBreakpoints::test_pdb_custom_cls (line 908) - Failed: nomatch: 'CustomDebugger'

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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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)?

@blueyed blueyed changed the title [WIP] Display line numbers in short test summary [RFC/WIP] Display line numbers in short test summary May 12, 2019
except AttributeError:
return nodeid

if isinstance(testloc.path, six.string_types):
Copy link
Member

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).

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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).

Copy link
Member

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.

Copy link
Contributor Author

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.

@pytest-dev pytest-dev deleted a comment from codecov bot Oct 31, 2019
@blueyed
Copy link
Contributor Author

blueyed commented Nov 1, 2019

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.

@blueyed blueyed closed this Nov 1, 2019
@blueyed blueyed deleted the tw-lnum-summary branch November 1, 2019 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants