diff --git a/AUTHORS b/AUTHORS index d43c4aa74..1f842780f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -61,6 +61,7 @@ Jaap Broekhuizen Jan Balster Janne Vanhala Jason R. Coombs +Javier Domingo Cansino John Towler Joshua Bronson Jurko Gospodnetić diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ec7ad5fea..b33ba167d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -60,8 +60,6 @@ time or change existing behaviors in order to make them less surprising/more use * -* - **New Features** * 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 `@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 .. _#1502: https://github.com/pytest-dev/pytest/pull/1502 .. _#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 .. _#1520: https://github.com/pytest-dev/pytest/pull/1520 .. _#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 .. _@tareqalayan: https://github.com/tareqalayan .. _@taschini: https://github.com/taschini +.. _@txomon: https://github.com/txomon 2.9.2 ===== diff --git a/_pytest/config.py b/_pytest/config.py index a667df75d..46c53ce68 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -27,6 +27,12 @@ class ConftestImportFailure(Exception): self.path = path 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): """ return exit code, after performing an in-process test run. diff --git a/testing/test_conftest.py b/testing/test_conftest.py index 90db7835c..377283eb9 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -408,3 +408,16 @@ def test_issue1073_conftest_special_objects(testdir): """) res = testdir.runpytest() 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]