Merge pull request #1746 from pytest-dev/conftest-exception-printing

Conftest exception printing
This commit is contained in:
Bruno Oliveira 2016-07-20 21:03:39 -03:00 committed by GitHub
commit eaa4ee3fdf
4 changed files with 26 additions and 2 deletions

View File

@ -61,6 +61,7 @@ Jaap Broekhuizen
Jan Balster Jan Balster
Janne Vanhala Janne Vanhala
Jason R. Coombs Jason R. Coombs
Javier Domingo Cansino
John Towler John Towler
Joshua Bronson Joshua Bronson
Jurko Gospodnetić Jurko Gospodnetić

View File

@ -60,8 +60,6 @@ time or change existing behaviors in order to make them less surprising/more use
* *
*
**New Features** **New Features**
* Support nose-style ``__test__`` attribute on methods of classes, * Support nose-style ``__test__`` attribute on methods of classes,
@ -251,6 +249,10 @@ time or change existing behaviors in order to make them less surprising/more use
Thanks `@Vogtinator`_ for reporting and `@RedBeardCode`_ and Thanks `@Vogtinator`_ for reporting and `@RedBeardCode`_ and
`@tomviner`_ for the PR. `@tomviner`_ for the PR.
* ``ConftestImportFailure`` now shows the traceback making it easier to
identify bugs in ``conftest.py`` files (`#1516`_). Thanks `@txomon`_ for
the PR.
* *
* *
@ -281,6 +283,7 @@ time or change existing behaviors in order to make them less surprising/more use
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479 .. _#1479: https://github.com/pytest-dev/pytest/issues/1479
.. _#1502: https://github.com/pytest-dev/pytest/pull/1502 .. _#1502: https://github.com/pytest-dev/pytest/pull/1502
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503 .. _#1503: https://github.com/pytest-dev/pytest/issues/1503
.. _#1516: https://github.com/pytest-dev/pytest/pull/1516
.. _#1519: https://github.com/pytest-dev/pytest/pull/1519 .. _#1519: https://github.com/pytest-dev/pytest/pull/1519
.. _#1520: https://github.com/pytest-dev/pytest/pull/1520 .. _#1520: https://github.com/pytest-dev/pytest/pull/1520
.. _#1526: https://github.com/pytest-dev/pytest/pull/1526 .. _#1526: https://github.com/pytest-dev/pytest/pull/1526
@ -333,6 +336,7 @@ time or change existing behaviors in order to make them less surprising/more use
.. _@sober7: https://github.com/sober7 .. _@sober7: https://github.com/sober7
.. _@tareqalayan: https://github.com/tareqalayan .. _@tareqalayan: https://github.com/tareqalayan
.. _@taschini: https://github.com/taschini .. _@taschini: https://github.com/taschini
.. _@txomon: https://github.com/txomon
2.9.2 2.9.2
===== =====

View File

@ -27,6 +27,12 @@ class ConftestImportFailure(Exception):
self.path = path self.path = path
self.excinfo = excinfo self.excinfo = excinfo
def __str__(self):
etype, evalue, etb = self.excinfo
formatted = traceback.format_tb(etb)
# The level of the tracebacks we want to print is hand crafted :(
return repr(evalue) + '\n' + ''.join(formatted[2:])
def main(args=None, plugins=None): def main(args=None, plugins=None):
""" return exit code, after performing an in-process test run. """ return exit code, after performing an in-process test run.

View File

@ -408,3 +408,16 @@ def test_issue1073_conftest_special_objects(testdir):
""") """)
res = testdir.runpytest() res = testdir.runpytest()
assert res.ret == 0 assert res.ret == 0
def test_conftest_exception_handling(testdir):
testdir.makeconftest('''
raise ValueError()
''')
testdir.makepyfile("""
def test_some():
pass
""")
res = testdir.runpytest()
assert res.ret == 4
assert 'raise ValueError()' in [line.strip() for line in res.errlines]