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

Method runtest

src/_pytest/unittest.py:292–320  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

290 pass
291
292 def runtest(self) -> None:
293 from _pytest.debugging import maybe_wrap_pytest_function_for_tracing
294
295 assert self._testcase is not None
296
297 maybe_wrap_pytest_function_for_tracing(self)
298
299 # Let the unittest framework handle async functions.
300 if is_async_function(self.obj):
301 # Type ignored because self acts as the TestResult, but is not actually one.
302 self._testcase(result=self) # type: ignore[arg-type]
303 else:
304 # When --pdb is given, we want to postpone calling tearDown() otherwise
305 # when entering the pdb prompt, tearDown() would have probably cleaned up
306 # instance variables, which makes it difficult to debug.
307 # Arguably we could always postpone tearDown(), but this changes the moment where the
308 # TestCase instance interacts with the results object, so better to only do it
309 # when absolutely needed.
310 if self.config.getoption("usepdb") and not _is_skipped(self.obj):
311 self._explicit_tearDown = self._testcase.tearDown
312 setattr(self._testcase, "tearDown", lambda *args: None)
313
314 # We need to update the actual bound method with self.obj, because
315 # wrap_pytest_function_for_tracing replaces self.obj by a wrapper.
316 setattr(self._testcase, self.name, self.obj)
317 try:
318 self._testcase(result=self) # type: ignore[arg-type]
319 finally:
320 delattr(self._testcase, self.name)
321
322 def _prunetraceback(
323 self, excinfo: _pytest._code.ExceptionInfo[BaseException]

Callers

nothing calls this directly

Calls 4

is_async_functionFunction · 0.90
_is_skippedFunction · 0.85
getoptionMethod · 0.45

Tested by

no test coverage detected