def timing_stats_panel(): return TestTimingStatsPanel( [ TestResult( test=Test( timer=_Timer(duration=4.0), fn=lambda: 1, description="test1", module_name="mod1", ), outcome=TestOutcome.FAIL, ), TestResult( test=Test( timer=_Timer(duration=3.0), fn=lambda: 1, description="test2", module_name="mod2", ), outcome=TestOutcome.FAIL, ), TestResult( test=Test( timer=_Timer(duration=5.0), fn=lambda: 1, description="test3", module_name="mod3", ), outcome=TestOutcome.PASS, ), ], num_tests_to_show=3, )
def _(outcome=outcome, expected_output=expected_output): assert expected_output == get_dot( TestResult( test=Test( timer=_Timer(duration=4.0), fn=lambda: 1, description="test1", module_name="mod1", ), outcome=outcome, ) )
def test_result() -> TestResult: @testable_test def _(): assert True return TestResult( test=Test( timer=_Timer(duration=4.0), fn=_, description="test1", module_name="mod1", ), outcome=TestOutcome.FAIL, )
def run(self, cache: FixtureCache, dry_run=False) -> "TestResult": # noqa: C901 with ExitStack() as stack: self.timer = stack.enter_context(_Timer()) if self.capture_output: stack.enter_context(redirect_stdout(self.sout)) stack.enter_context(redirect_stderr(self.serr)) if dry_run: with closing(self.sout), closing(self.serr): result = TestResult(self, TestOutcome.DRYRUN) return result if isinstance(self.marker, SkipMarker) and self.marker.active: with closing(self.sout), closing(self.serr): result = TestResult(self, TestOutcome.SKIP) return result try: resolved_args = self.resolver.resolve_args(cache) self.format_description(resolved_args) if self.is_async_test: coro = self.fn(**resolved_args) asyncio.get_event_loop().run_until_complete(coro) else: self.fn(**resolved_args) except FixtureError as e: outcome = TestOutcome.FAIL error: Optional[BaseException] = e except BdbQuit: # We don't want to treat the user quitting the debugger # as an exception, so we'll ignore BdbQuit. This will # also prevent a large pdb-internal stack trace flooding # the terminal. pass except (Exception, SystemExit) as e: error = e if isinstance(self.marker, XfailMarker) and self.marker.active: outcome = TestOutcome.XFAIL else: outcome = TestOutcome.FAIL else: error = None if isinstance(self.marker, XfailMarker) and self.marker.active: outcome = TestOutcome.XPASS else: outcome = TestOutcome.PASS with closing(self.sout), closing(self.serr): if outcome in (TestOutcome.PASS, TestOutcome.SKIP): result = TestResult(self, outcome) else: if isinstance(error, AssertionError): error.error_line = traceback.extract_tb( # type: ignore[attr-defined] error.__traceback__, limit=-1)[0].lineno result = TestResult( self, outcome, error, captured_stdout=self.sout.getvalue(), captured_stderr=self.serr.getvalue(), ) return result