MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_exact_teardown_issue1206

Method test_exact_teardown_issue1206

testing/test_runner.py:317–353  ·  view source on GitHub ↗

Issue shadowing error with wrong number of arguments on teardown_method.

(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

315 assert reps[5].failed
316
317 def test_exact_teardown_issue1206(self, pytester: Pytester) -> None:
318 """Issue shadowing error with wrong number of arguments on teardown_method."""
319 rec = pytester.inline_runsource(
320 """
321 import pytest
322
323 class TestClass(object):
324 def teardown_method(self, x, y, z):
325 pass
326
327 def test_method(self):
328 assert True
329 """
330 )
331 reps = rec.getreports("pytest_runtest_logreport")
332 print(reps)
333 assert len(reps) == 3
334 #
335 assert reps[0].nodeid.endswith("test_method")
336 assert reps[0].passed
337 assert reps[0].when == "setup"
338 #
339 assert reps[1].nodeid.endswith("test_method")
340 assert reps[1].passed
341 assert reps[1].when == "call"
342 #
343 assert reps[2].nodeid.endswith("test_method")
344 assert reps[2].failed
345 assert reps[2].when == "teardown"
346 longrepr = reps[2].longrepr
347 assert isinstance(longrepr, ExceptionChainRepr)
348 assert longrepr.reprcrash
349 assert longrepr.reprcrash.message in (
350 "TypeError: teardown_method() missing 2 required positional arguments: 'y' and 'z'",
351 # Python >= 3.10
352 "TypeError: TestClass.teardown_method() missing 2 required positional arguments: 'y' and 'z'",
353 )
354
355 def test_failure_in_setup_function_ignores_custom_repr(
356 self, pytester: Pytester

Callers

nothing calls this directly

Calls 2

inline_runsourceMethod · 0.45
getreportsMethod · 0.45

Tested by

no test coverage detected