From d8b620e0231c7326bddabb1b661fb2c140a5f992 Mon Sep 17 00:00:00 2001 From: Rafal Semik Date: Thu, 2 Feb 2023 17:22:53 +0100 Subject: [PATCH] Propagate timestamps from CallInfo to TestReport objects TestReport objects stored only the information about stage duration. This is not enough to correlate pytest stages with external events. Timestamps are already there in CallInfo. They just needed to be propagated to TestReport objects, so that they can be read when TestReports are exported externally (for example with --reportlog option) --- AUTHORS | 1 + changelog/10710.improvement.rst | 1 + src/_pytest/reports.py | 11 +++++++++++ 3 files changed, 13 insertions(+) create mode 100644 changelog/10710.improvement.rst diff --git a/AUTHORS b/AUTHORS index 2f50a2950..0395feceb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -297,6 +297,7 @@ Ram Rachum Ran Benita Raphael Castaneda Raphael Pierzina +Rafal Semik Raquel Alegre Ravi Chandra Robert Holt diff --git a/changelog/10710.improvement.rst b/changelog/10710.improvement.rst new file mode 100644 index 000000000..1f440c59b --- /dev/null +++ b/changelog/10710.improvement.rst @@ -0,0 +1 @@ +Added ``start`` and ``stop`` timestamps to ``TestReport`` objects exported to --reportlog. diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 1b2821c71..102559384 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -262,6 +262,8 @@ class TestReport(BaseReport): when: "Literal['setup', 'call', 'teardown']", sections: Iterable[Tuple[str, str]] = (), duration: float = 0, + start: float = 0, + stop: float = 0, user_properties: Optional[Iterable[Tuple[str, object]]] = None, **extra, ) -> None: @@ -299,6 +301,11 @@ class TestReport(BaseReport): #: Time it took to run just the test. self.duration: float = duration + #: The system time when the call started, in seconds since the epoch. + self.start: float = start + #: The system time when the call ended, in seconds since the epoch. + self.stop: float = stop + self.__dict__.update(extra) def __repr__(self) -> str: @@ -317,6 +324,8 @@ class TestReport(BaseReport): # Remove "collect" from the Literal type -- only for collection calls. assert when != "collect" duration = call.duration + start = call.start + stop = call.stop keywords = {x: 1 for x in item.keywords} excinfo = call.excinfo sections = [] @@ -361,6 +370,8 @@ class TestReport(BaseReport): when, sections, duration, + start, + stop, user_properties=item.user_properties, )