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

Class RunResult

src/_pytest/pytester.py:519–622  ·  view source on GitHub ↗

The result of running a command from :class:`~pytest.Pytester`.

Source from the content-addressed store, hash-verified

517
518@final
519class RunResult:
520 """The result of running a command from :class:`~pytest.Pytester`."""
521
522 def __init__(
523 self,
524 ret: Union[int, ExitCode],
525 outlines: List[str],
526 errlines: List[str],
527 duration: float,
528 ) -> None:
529 try:
530 self.ret: Union[int, ExitCode] = ExitCode(ret)
531 """The return value."""
532 except ValueError:
533 self.ret = ret
534 self.outlines = outlines
535 """List of lines captured from stdout."""
536 self.errlines = errlines
537 """List of lines captured from stderr."""
538 self.stdout = LineMatcher(outlines)
539 """:class:`~pytest.LineMatcher` of stdout.
540
541 Use e.g. :func:`str(stdout) <pytest.LineMatcher.__str__()>` to reconstruct stdout, or the commonly used
542 :func:`stdout.fnmatch_lines() <pytest.LineMatcher.fnmatch_lines()>` method.
543 """
544 self.stderr = LineMatcher(errlines)
545 """:class:`~pytest.LineMatcher` of stderr."""
546 self.duration = duration
547 """Duration in seconds."""
548
549 def __repr__(self) -> str:
550 return (
551 "<RunResult ret=%s len(stdout.lines)=%d len(stderr.lines)=%d duration=%.2fs>"
552 % (self.ret, len(self.stdout.lines), len(self.stderr.lines), self.duration)
553 )
554
555 def parseoutcomes(self) -> Dict[str, int]:
556 """Return a dictionary of outcome noun -> count from parsing the terminal
557 output that the test process produced.
558
559 The returned nouns will always be in plural form::
560
561 ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ====
562
563 Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``.
564 """
565 return self.parse_summary_nouns(self.outlines)
566
567 @classmethod
568 def parse_summary_nouns(cls, lines) -> Dict[str, int]:
569 """Extract the nouns from a pytest terminal summary line.
570
571 It always returns the plural noun for consistency::
572
573 ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ====
574
575 Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``.
576 """

Callers 2

runpytest_inprocessMethod · 0.85
runMethod · 0.85

Calls

no outgoing calls

Tested by 2

runpytest_inprocessMethod · 0.68
runMethod · 0.68