Skip to content

Commit eaa4ee3

Browse files
authored
Merge pull request #1746 from pytest-dev/conftest-exception-printing
Conftest exception printing
2 parents 93aae98 + e0f08a7 commit eaa4ee3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Jaap Broekhuizen
6161
Jan Balster
6262
Janne Vanhala
6363
Jason R. Coombs
64+
Javier Domingo Cansino
6465
John Towler
6566
Joshua Bronson
6667
Jurko Gospodnetić

CHANGELOG.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ time or change existing behaviors in order to make them less surprising/more use
6060

6161
*
6262

63-
*
64-
6563
**New Features**
6664

6765
* 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
251249
Thanks `@Vogtinator`_ for reporting and `@RedBeardCode`_ and
252250
`@tomviner`_ for the PR.
253251

252+
* ``ConftestImportFailure`` now shows the traceback making it easier to
253+
identify bugs in ``conftest.py`` files (`#1516`_). Thanks `@txomon`_ for
254+
the PR.
255+
254256
*
255257

256258
*
@@ -281,6 +283,7 @@ time or change existing behaviors in order to make them less surprising/more use
281283
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479
282284
.. _#1502: https://github.com/pytest-dev/pytest/pull/1502
283285
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503
286+
.. _#1516: https://github.com/pytest-dev/pytest/pull/1516
284287
.. _#1519: https://github.com/pytest-dev/pytest/pull/1519
285288
.. _#1520: https://github.com/pytest-dev/pytest/pull/1520
286289
.. _#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
333336
.. _@sober7: https://github.com/sober7
334337
.. _@tareqalayan: https://github.com/tareqalayan
335338
.. _@taschini: https://github.com/taschini
339+
.. _@txomon: https://github.com/txomon
336340

337341
2.9.2
338342
=====

_pytest/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def __init__(self, path, excinfo):
2727
self.path = path
2828
self.excinfo = excinfo
2929

30+
def __str__(self):
31+
etype, evalue, etb = self.excinfo
32+
formatted = traceback.format_tb(etb)
33+
# The level of the tracebacks we want to print is hand crafted :(
34+
return repr(evalue) + '\n' + ''.join(formatted[2:])
35+
3036

3137
def main(args=None, plugins=None):
3238
""" return exit code, after performing an in-process test run.

testing/test_conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,16 @@ def test_some():
408408
""")
409409
res = testdir.runpytest()
410410
assert res.ret == 0
411+
412+
413+
def test_conftest_exception_handling(testdir):
414+
testdir.makeconftest('''
415+
raise ValueError()
416+
''')
417+
testdir.makepyfile("""
418+
def test_some():
419+
pass
420+
""")
421+
res = testdir.runpytest()
422+
assert res.ret == 4
423+
assert 'raise ValueError()' in [line.strip() for line in res.errlines]

0 commit comments

Comments
 (0)