Skip to content

Commit 66e66f6

Browse files
Merge pull request #1605 from guyzmo/issue/1604
Fixed issue shadowing error when missing argument on teardown_method
2 parents 577cce2 + accd962 commit 66e66f6

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-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: 3 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

@@ -15,6 +16,7 @@
1516
`@marscher`. Thanks `@nicoddemus` for his help.
1617

1718
.. _#1580: https://github.com/pytest-dev/pytest/issues/1580
19+
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
1820

1921
.. _@graingert: https://github.com/graingert
2022

_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"

testing/test_runner.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,39 @@ def teardown_function(func):
228228
assert reps[5].nodeid.endswith("test_func")
229229
assert reps[5].failed
230230

231+
def test_exact_teardown_issue1206(self, testdir):
232+
rec = testdir.inline_runsource("""
233+
import pytest
234+
235+
class TestClass:
236+
def teardown_method(self):
237+
pass
238+
239+
def test_method(self):
240+
assert True
241+
""")
242+
reps = rec.getreports("pytest_runtest_logreport")
243+
print (reps)
244+
assert len(reps) == 3
245+
#
246+
assert reps[0].nodeid.endswith("test_method")
247+
assert reps[0].passed
248+
assert reps[0].when == 'setup'
249+
#
250+
assert reps[1].nodeid.endswith("test_method")
251+
assert reps[1].passed
252+
assert reps[1].when == 'call'
253+
#
254+
assert reps[2].nodeid.endswith("test_method")
255+
assert reps[2].failed
256+
assert reps[2].when == "teardown"
257+
assert reps[2].longrepr.reprcrash.message in (
258+
# python3 error
259+
'TypeError: teardown_method() takes 1 positional argument but 2 were given',
260+
# python2 error
261+
'TypeError: teardown_method() takes exactly 1 argument (2 given)'
262+
)
263+
231264
def test_failure_in_setup_function_ignores_custom_repr(self, testdir):
232265
testdir.makepyfile(conftest="""
233266
import pytest

0 commit comments

Comments
 (0)