(self, result=None)
| 630 | function(*args, **kwargs) |
| 631 | |
| 632 | def run(self, result=None): |
| 633 | if result is None: |
| 634 | result = self.defaultTestResult() |
| 635 | startTestRun = getattr(result, 'startTestRun', None) |
| 636 | stopTestRun = getattr(result, 'stopTestRun', None) |
| 637 | if startTestRun is not None: |
| 638 | startTestRun() |
| 639 | else: |
| 640 | stopTestRun = None |
| 641 | |
| 642 | result.startTest(self) |
| 643 | try: |
| 644 | testMethod = getattr(self, self._testMethodName) |
| 645 | if (getattr(self.__class__, "__unittest_skip__", False) or |
| 646 | getattr(testMethod, "__unittest_skip__", False)): |
| 647 | # If the class or method was skipped. |
| 648 | skip_why = (getattr(self.__class__, '__unittest_skip_why__', '') |
| 649 | or getattr(testMethod, '__unittest_skip_why__', '')) |
| 650 | _addSkip(result, self, skip_why) |
| 651 | return result |
| 652 | |
| 653 | expecting_failure = ( |
| 654 | getattr(self, "__unittest_expecting_failure__", False) or |
| 655 | getattr(testMethod, "__unittest_expecting_failure__", False) |
| 656 | ) |
| 657 | outcome = _Outcome(result) |
| 658 | start_time = time.perf_counter() |
| 659 | try: |
| 660 | self._outcome = outcome |
| 661 | |
| 662 | with outcome.testPartExecutor(self): |
| 663 | self._callSetUp() |
| 664 | if outcome.success: |
| 665 | outcome.expecting_failure = expecting_failure |
| 666 | with outcome.testPartExecutor(self): |
| 667 | self._callTestMethod(testMethod) |
| 668 | outcome.expecting_failure = False |
| 669 | with outcome.testPartExecutor(self): |
| 670 | self._callTearDown() |
| 671 | self.doCleanups() |
| 672 | self._addDuration(result, (time.perf_counter() - start_time)) |
| 673 | |
| 674 | if outcome.success: |
| 675 | if expecting_failure: |
| 676 | if outcome.expectedFailure: |
| 677 | self._addExpectedFailure(result, outcome.expectedFailure) |
| 678 | else: |
| 679 | self._addUnexpectedSuccess(result) |
| 680 | else: |
| 681 | result.addSuccess(self) |
| 682 | return result |
| 683 | finally: |
| 684 | # explicitly break reference cycle: |
| 685 | # outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure |
| 686 | outcome.expectedFailure = None |
| 687 | outcome = None |
| 688 | |
| 689 | # clear the outcome, no more needed |
no test coverage detected