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)
This commit is contained in:
Rafal Semik 2023-02-02 17:22:53 +01:00
parent 4a46ee8bc9
commit d8b620e023
3 changed files with 13 additions and 0 deletions

View File

@ -297,6 +297,7 @@ Ram Rachum
Ran Benita Ran Benita
Raphael Castaneda Raphael Castaneda
Raphael Pierzina Raphael Pierzina
Rafal Semik
Raquel Alegre Raquel Alegre
Ravi Chandra Ravi Chandra
Robert Holt Robert Holt

View File

@ -0,0 +1 @@
Added ``start`` and ``stop`` timestamps to ``TestReport`` objects exported to --reportlog.

View File

@ -262,6 +262,8 @@ class TestReport(BaseReport):
when: "Literal['setup', 'call', 'teardown']", when: "Literal['setup', 'call', 'teardown']",
sections: Iterable[Tuple[str, str]] = (), sections: Iterable[Tuple[str, str]] = (),
duration: float = 0, duration: float = 0,
start: float = 0,
stop: float = 0,
user_properties: Optional[Iterable[Tuple[str, object]]] = None, user_properties: Optional[Iterable[Tuple[str, object]]] = None,
**extra, **extra,
) -> None: ) -> None:
@ -299,6 +301,11 @@ class TestReport(BaseReport):
#: Time it took to run just the test. #: Time it took to run just the test.
self.duration: float = duration 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) self.__dict__.update(extra)
def __repr__(self) -> str: def __repr__(self) -> str:
@ -317,6 +324,8 @@ class TestReport(BaseReport):
# Remove "collect" from the Literal type -- only for collection calls. # Remove "collect" from the Literal type -- only for collection calls.
assert when != "collect" assert when != "collect"
duration = call.duration duration = call.duration
start = call.start
stop = call.stop
keywords = {x: 1 for x in item.keywords} keywords = {x: 1 for x in item.keywords}
excinfo = call.excinfo excinfo = call.excinfo
sections = [] sections = []
@ -361,6 +370,8 @@ class TestReport(BaseReport):
when, when,
sections, sections,
duration, duration,
start,
stop,
user_properties=item.user_properties, user_properties=item.user_properties,
) )