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

Class RunResult

src/_pytest/pytester.py:519–624  ·  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: int | ExitCode,
525 outlines: list[str],
526 errlines: list[str],
527 duration: float,
528 ) -> None:
529 try:
530 self.ret: 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 f"<RunResult ret={self.ret!s} "
552 f"len(stdout.lines)={len(self.stdout.lines)} "
553 f"len(stderr.lines)={len(self.stderr.lines)} "
554 f"duration={self.duration:.2f}s>"
555 )
556
557 def parseoutcomes(self) -> dict[str, int]:
558 """Return a dictionary of outcome noun -> count from parsing the terminal
559 output that the test process produced.
560
561 The returned nouns will always be in plural form::
562
563 ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ====
564
565 Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``.
566 """
567 return self.parse_summary_nouns(self.outlines)
568
569 @classmethod
570 def parse_summary_nouns(cls, lines) -> dict[str, int]:
571 """Extract the nouns from a pytest terminal summary line.
572
573 It always returns the plural noun for consistency::
574
575 ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ====
576

Callers 2

runpytest_inprocessMethod · 0.85
runMethod · 0.85

Calls

no outgoing calls

Tested by 2

runpytest_inprocessMethod · 0.68
runMethod · 0.68