MCPcopy
hub / github.com/pytest-dev/pytest / addSkip

Method addSkip

src/_pytest/unittest.py:314–345  ·  view source on GitHub ↗
(
        self, testcase: unittest.TestCase, reason: str, *, handle_subtests: bool = True
    )

Source from the content-addressed store, hash-verified

312 self._addexcinfo(rawexcinfo)
313
314 def addSkip(
315 self, testcase: unittest.TestCase, reason: str, *, handle_subtests: bool = True
316 ) -> None:
317 from unittest.case import _SubTest # type: ignore[attr-defined]
318
319 def add_skip() -> None:
320 try:
321 raise skip.Exception(reason, _use_item_location=True)
322 except skip.Exception:
323 self._addexcinfo(sys.exc_info())
324
325 if not handle_subtests:
326 add_skip()
327 return
328
329 if isinstance(testcase, _SubTest):
330 add_skip()
331 if self._excinfo is not None:
332 exc_info = self._excinfo[-1]
333 self.addSubTest(testcase.test_case, testcase, exc_info)
334 else:
335 # For python < 3.11: the non-subtest skips have to be added by `add_skip` only after all subtest
336 # failures are processed by `_addSubTest`: `self.instance._outcome` has no attribute
337 # `skipped/errors` anymore.
338 # We also need to check if `self.instance._outcome` is `None` (this happens if the test
339 # class/method is decorated with `unittest.skip`, see pytest-dev/pytest-subtests#173).
340 if sys.version_info < (3, 11) and self.instance._outcome is not None:
341 subtest_errors, _ = self._obtain_errors_and_skips()
342 if len(subtest_errors) == 0:
343 add_skip()
344 else:
345 add_skip()
346
347 def addExpectedFailure(
348 self,

Callers 1

addSubTestMethod · 0.95

Calls 2

addSubTestMethod · 0.95

Tested by

no test coverage detected