From daf81305b8bb3bf915e1a8a2e8a888c68f99b1b5 Mon Sep 17 00:00:00 2001 From: Roberto Aldera <51328612+roberto-aldera@users.noreply.github.com> Date: Sun, 14 May 2023 18:46:27 +0200 Subject: [PATCH] Move test status structure --- src/_pytest/hookspec.py | 3 ++- src/_pytest/terminal.py | 31 ++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index a3706bb10..16251781e 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -40,6 +40,7 @@ if TYPE_CHECKING: from _pytest.reports import TestReport from _pytest.runner import CallInfo from _pytest.terminal import TerminalReporter + from _pytest.terminal import TestStatus from _pytest.compat import LEGACY_PATH @@ -805,7 +806,7 @@ def pytest_report_collectionfinish( # type:ignore[empty-body] @hookspec(firstresult=True) def pytest_report_teststatus( # type:ignore[empty-body] report: Union["CollectReport", "TestReport"], config: "Config" -) -> "TerminalReporter.TestStatus": +) -> "TestStatus": """Return result-category, shortletter and verbose word for status reporting. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index d7fad458c..753f12de6 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -113,6 +113,21 @@ class MoreQuietAction(argparse.Action): namespace.quiet = getattr(namespace, "quiet", 0) + 1 +class TestStatus(NamedTuple): + """Used to store the test status result category, shortletter and verbose word. + For example ``"rerun", "R", ("RERUN", {"yellow": True})``. + + category: the class of result, for example “passed”, “skipped”, “error”, or the empty string + letter: the shortletter shown as testing progresses, for example ".", "s", "E", or the empty string. + word: verbose word is shown as testing progresses in verbose mode, for example "PASSED", "SKIPPED", + "ERROR", or the empty string. + """ + + category: str + letter: str + word: Union[str, Tuple[str, Mapping[str, bool]]] + + def pytest_addoption(parser: Parser) -> None: group = parser.getgroup("terminal reporting", "Reporting", after="general") group._addoption( @@ -546,25 +561,11 @@ class TerminalReporter: self.write_fspath_result(nodeid, "") self.flush() - class TestStatus(NamedTuple): - """Used to store the test status result category, shortletter and verbose word. - For example ``"rerun", "R", ("RERUN", {"yellow": True})``. - - category: the class of result, for example “passed”, “skipped”, “error”, or the empty string - letter: the shortletter shown as testing progresses, for example ".", "s", "E", or the empty string. - word: verbose word is shown as testing progresses in verbose mode, for example "PASSED", "SKIPPED", - "ERROR", or the empty string. - """ - - category: str - letter: str - word: Union[str, Tuple[str, Mapping[str, bool]]] - def pytest_runtest_logreport(self, report: TestReport) -> None: self._tests_ran = True rep = report - res = self.TestStatus( + res = TestStatus( *self.config.hook.pytest_report_teststatus(report=rep, config=self.config) ) category, letter, word = res.category, res.letter, res.word