Move test status structure

This commit is contained in:
Roberto Aldera 2023-05-14 18:46:27 +02:00
parent d3502ac4d8
commit daf81305b8
No known key found for this signature in database
2 changed files with 18 additions and 16 deletions

View File

@ -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.

View File

@ -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