Skip to content

Commit

Permalink
junitxml: add timezone to testsuite timestamp (#12491)
Browse files Browse the repository at this point in the history
Signed-off-by: joseph-sentry <[email protected]>
Co-authored-by: Ronny Pfannschmidt <[email protected]>
  • Loading branch information
joseph-sentry and RonnyPfannschmidt authored Jun 27, 2024
1 parent f74e947 commit 0ed2d79
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Jordan Guymon
Jordan Moldow
Jordan Speicher
Joseph Hunkeler
Joseph Sawaya
Josh Karpel
Joshua Bronson
Jurko Gospodnetić
Expand Down
1 change: 1 addition & 0 deletions changelog/7662.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added timezone information to the testsuite timestamp in the JUnit XML report.
5 changes: 4 additions & 1 deletion src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import annotations

from datetime import datetime
from datetime import timezone
import functools
import os
import platform
Expand Down Expand Up @@ -664,7 +665,9 @@ def pytest_sessionfinish(self) -> None:
skipped=str(self.stats["skipped"]),
tests=str(numtests),
time=f"{suite_time_delta:.3f}",
timestamp=datetime.fromtimestamp(self.suite_start_time).isoformat(),
timestamp=datetime.fromtimestamp(self.suite_start_time, timezone.utc)
.astimezone()
.isoformat(),
hostname=platform.node(),
)
global_properties = self._get_global_properties_node()
Expand Down
7 changes: 4 additions & 3 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

from datetime import datetime
from datetime import timezone
import os
from pathlib import Path
import platform
Expand Down Expand Up @@ -218,11 +219,11 @@ def test_pass():
pass
"""
)
start_time = datetime.now()
start_time = datetime.now(timezone.utc)
result, dom = run_and_parse(family=xunit_family)
node = dom.find_first_by_tag("testsuite")
timestamp = datetime.strptime(node["timestamp"], "%Y-%m-%dT%H:%M:%S.%f")
assert start_time <= timestamp < datetime.now()
timestamp = datetime.strptime(node["timestamp"], "%Y-%m-%dT%H:%M:%S.%f%z")
assert start_time <= timestamp < datetime.now(timezone.utc)

def test_timing_function(
self, pytester: Pytester, run_and_parse: RunAndParse, mock_timing
Expand Down

0 comments on commit 0ed2d79

Please sign in to comment.