Skip to content

Commit cce91c2

Browse files
committed
Add a ISO-8601 timestamp to every testsuite and testcase in the XML-report.
1 parent 8e53812 commit cce91c2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tests/builder_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def test_add_time_attribute_on_end_context(self):
8383

8484
element.attributes['time'].value
8585

86+
def test_add_timestamp_attribute_on_end_context(self):
87+
self.root.begin('testsuite', 'name')
88+
element = self.root.end()
89+
90+
element.attributes['timestamp'].value
91+
8692

8793
class TestXMLBuilderTest(unittest.TestCase):
8894
"""TestXMLBuilder test cases.

xmlrunner/builder.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import sys
3+
import datetime
34
import time
45
import six
56

@@ -80,6 +81,7 @@ def end(self):
8081
"""
8182
self._stop_time = time.time()
8283
self.element.setAttribute('time', self.elapsed_time())
84+
self.element.setAttribute('timestamp', self.timestamp())
8385
self._set_result_counters()
8486
return self.element
8587

@@ -121,6 +123,11 @@ def elapsed_time(self):
121123
"""
122124
return format(self._stop_time - self._start_time, '.3f')
123125

126+
def timestamp(self):
127+
"""Returns the time the context ended as ISO-8601-formatted timestamp.
128+
"""
129+
return datetime.datetime.fromtimestamp(self._stop_time).replace(microsecond=0).isoformat()
130+
124131

125132
class TestXMLBuilder(object):
126133
"""This class encapsulates most rules needed to create a XML test report

0 commit comments

Comments
 (0)