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

Show traceback during collection #1979

Merged

Conversation

nicoddemus
Copy link
Member

@nicoddemus nicoddemus commented Oct 4, 2016

Fixes #1976.

Here's the output:

master

______________________ ERROR collecting .tmp/test_foo.py ______________________
ImportError while importing test module 'C:\pytest\.tmp\test_foo.py'.
Original error message:
'cannot import name 'non_existing''
Make sure your test modules/packages have valid Python names.
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!

this PR

______________________ ERROR collecting .tmp/test_foo.py ______________________
ImportError while importing test module 'C:\pytest\.tmp\test_foo.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_foo.py:1: in <module>
    import foo
foo.py:1: in <module>
    from bar import non_existing
E   ImportError: cannot import name 'non_existing'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!

this PR with -vv

______________________ ERROR collecting .tmp/test_foo.py ______________________
ImportError while importing test module 'C:\pytest\.tmp\test_foo.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\_pytest\python.py:415: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
..\.env35\lib\site-packages\py\_path\local.py:650: in pyimport
    __import__(modname)
..\_pytest\assertion\rewrite.py:207: in load_module
    py.builtin.exec_(co, mod.__dict__)
test_foo.py:1: in <module>
    import foo
foo.py:1: in <module>
    from bar import non_existing
E   ImportError: cannot import name 'non_existing'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!

import not_exists
""")
result = testdir.runpytest(p)
assert "__import__" not in result.stdout.str(), "too long traceback"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was here to explicitly cut back the traceback from the error message, but unfortunately this makes it more difficult to find bugs.

exc_info = ExceptionInfo()
if self.config.getoption('verbose') < 2:
exc_info.traceback = exc_info.traceback.filter(filter_traceback)
exc_repr = exc_info.getrepr(style='short') if exc_info.traceback else exc_info.exconly()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to hard-code it to short because it is usually enough to track import problems and long may generate too much output during collection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please a comment in the code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, good point.

@coveralls
Copy link

coveralls commented Oct 4, 2016

Coverage Status

Coverage decreased (-0.04%) to 92.909% when pulling a1d446b on nicoddemus:show-traceback-during-collection into fc02003 on pytest-dev:master.

@nicoddemus
Copy link
Member Author

No idea why the py35-trial failed, will investigate it later.

@nicoddemus nicoddemus merged commit cf13355 into pytest-dev:master Oct 5, 2016
@nicoddemus nicoddemus deleted the show-traceback-during-collection branch October 5, 2016 19:18
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.

None yet

3 participants