Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test case as failed but resumes execution at the end of the enclosed block, allowing furthe
(self, msg=_subtest_msg_sentinel, **params)
| 543 | |
| 544 | @contextlib.contextmanager |
| 545 | def subTest(self, msg=_subtest_msg_sentinel, **params): |
| 546 | """Return a context manager that will return the enclosed block |
| 547 | of code in a subtest identified by the optional message and |
| 548 | keyword parameters. A failure in the subtest marks the test |
| 549 | case as failed but resumes execution at the end of the enclosed |
| 550 | block, allowing further test code to be executed. |
| 551 | """ |
| 552 | if self._outcome is None or not self._outcome.result_supports_subtests: |
| 553 | yield |
| 554 | return |
| 555 | parent = self._subtest |
| 556 | if parent is None: |
| 557 | params_map = _OrderedChainMap(params) |
| 558 | else: |
| 559 | params_map = parent.params.new_child(params) |
| 560 | self._subtest = _SubTest(self, msg, params_map) |
| 561 | try: |
| 562 | with self._outcome.testPartExecutor(self._subtest, subTest=True): |
| 563 | yield |
| 564 | if not self._outcome.success: |
| 565 | result = self._outcome.result |
| 566 | if result is not None and result.failfast: |
| 567 | raise _ShouldStop |
| 568 | elif self._outcome.expectedFailure: |
| 569 | # If the test is expecting a failure, we really want to |
| 570 | # stop now and register the expected failure. |
| 571 | raise _ShouldStop |
| 572 | finally: |
| 573 | self._subtest = parent |
| 574 | |
| 575 | def _addExpectedFailure(self, result, exc_info): |
| 576 | try: |