Skip to content

Commit fc7c104

Browse files
committed
Fixed issue shadowing error when missing argument on teardown_method
When the method argument is missing on teardown_method, the traceback is 100% internal to pytest, which with default options get pruned. Then that traceback is empty, leading to a new exception as a traceback shall not be empty. This PR fixes that issue by pushing back the last stack on the traceback, when the stacktrace is empty after pruning. Then the output is still pruned, but gives meaningful information with the item where it failed on the stack. * fixes issue #1604 Signed-off-by: Guyzmo <guyzmo+github@m0g.net>
1 parent 577cce2 commit fc7c104

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,4 @@ Thomas Grainger
9191
Tom Viner
9292
Trevor Bekolay
9393
Wouter van Ackooy
94+
Bernard Pratz

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* Text documents without any doctests no longer appear as "skipped".
77
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).
88

9-
*
9+
* Fix internal error issue when `method` argument is missing for
10+
`teardown_method`. Fixes (`#1605`).
1011

1112
*
1213

_pytest/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,10 @@ def _repr_failure_py(self, excinfo, style=None):
392392
if self.config.option.fulltrace:
393393
style="long"
394394
else:
395+
tb = _pytest._code.Traceback([excinfo.traceback[-1]])
395396
self._prunetraceback(excinfo)
397+
if len(excinfo.traceback) == 0:
398+
excinfo.traceback = tb
396399
tbfilter = False # prunetraceback already does it
397400
if style == "auto":
398401
style = "long"

0 commit comments

Comments
 (0)