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>
This commit is contained in:
@@ -228,6 +228,39 @@ class BaseFunctionalTests:
|
||||
assert reps[5].nodeid.endswith("test_func")
|
||||
assert reps[5].failed
|
||||
|
||||
def test_exact_teardown_issue1206(self, testdir):
|
||||
rec = testdir.inline_runsource("""
|
||||
import pytest
|
||||
|
||||
class TestClass:
|
||||
def teardown_method(self):
|
||||
pass
|
||||
|
||||
def test_method(self):
|
||||
assert True
|
||||
""")
|
||||
reps = rec.getreports("pytest_runtest_logreport")
|
||||
print (reps)
|
||||
assert len(reps) == 3
|
||||
#
|
||||
assert reps[0].nodeid.endswith("test_method")
|
||||
assert reps[0].passed
|
||||
assert reps[0].when == 'setup'
|
||||
#
|
||||
assert reps[1].nodeid.endswith("test_method")
|
||||
assert reps[1].passed
|
||||
assert reps[1].when == 'call'
|
||||
#
|
||||
assert reps[2].nodeid.endswith("test_method")
|
||||
assert reps[2].failed
|
||||
assert reps[2].when == "teardown"
|
||||
assert reps[2].longrepr.reprcrash.message in (
|
||||
# python3 error
|
||||
'TypeError: teardown_method() takes 1 positional argument but 2 were given',
|
||||
# python2 error
|
||||
'TypeError: teardown_method() takes exactly 1 argument (2 given)'
|
||||
)
|
||||
|
||||
def test_failure_in_setup_function_ignores_custom_repr(self, testdir):
|
||||
testdir.makepyfile(conftest="""
|
||||
import pytest
|
||||
|
||||
Reference in New Issue
Block a user