Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.6] Add hostname and timestamp to JUnit XML testsuite tag (#5692) #6332

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5471.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JUnit XML now includes a timestamp and hostname in the testsuite tag.
4 changes: 4 additions & 0 deletions src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

import functools
import os
import platform
import re
import sys
import time
from datetime import datetime

import py
import six
Expand Down Expand Up @@ -676,6 +678,8 @@ def pytest_sessionfinish(self):
skipped=self.stats["skipped"],
tests=numtests,
time="%.3f" % suite_time_delta,
timestamp=datetime.fromtimestamp(self.suite_start_time).isoformat(),
hostname=platform.node(),
)
logfile.write(Junit.testsuites([suite_node]).unicode(indent=0))
logfile.close()
Expand Down
26 changes: 26 additions & 0 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from __future__ import print_function

import os
import platform
import sys
from datetime import datetime
from xml.dom import minidom

import py
Expand Down Expand Up @@ -145,6 +147,30 @@ def test_xpass():
node = dom.find_first_by_tag("testsuite")
node.assert_attr(name="pytest", errors=1, failures=2, skipped=1, tests=5)

def test_hostname_in_xml(self, testdir):
testdir.makepyfile(
"""
def test_pass():
pass
"""
)
result, dom = runandparse(testdir)
node = dom.find_first_by_tag("testsuite")
node.assert_attr(hostname=platform.node())

def test_timestamp_in_xml(self, testdir):
testdir.makepyfile(
"""
def test_pass():
pass
"""
)
start_time = datetime.now()
result, dom = runandparse(testdir)
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()

def test_timing_function(self, testdir):
testdir.makepyfile(
"""
Expand Down