Skip to content

Commit

Permalink
Merge pull request #33 from stb-tester/junit-timestamp-tz
Browse files Browse the repository at this point in the history
JUnit XML output: Include timezone information in XML
  • Loading branch information
drothlis committed Sep 8, 2020
2 parents 81bd323 + f2a02dd commit b6c717b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
5 changes: 3 additions & 2 deletions requirements.txt
Expand Up @@ -5,8 +5,9 @@ requests

# Dependencies of the tests
requests-mock
pylint==1.9.3
astroid==1.6.5
pylint==1.8.3
astroid==1.6.0
flask==1.1.1
isort==4.3.4
subprocess32==3.5.4 ; python_version=='2.7'
werkzeug==0.15.5
27 changes: 23 additions & 4 deletions stbt_rig.py
Expand Up @@ -6,7 +6,7 @@
For more details, and to get the latest version of this script, see
<https://github.com/stb-tester/stbt-rig>.
Copyright 2017-2019 Stb-tester.com Ltd. <support@stb-tester.com>
Copyright 2017-2020 Stb-tester.com Ltd. <support@stb-tester.com>
Released under the MIT license.
"""

Expand Down Expand Up @@ -839,7 +839,8 @@ def list_results(self):

def list_results_xml(self):
r = self.portal._get(
'/api/v2/results.xml', params={'filter': 'job:%s' % self.job_uid})
'/api/v2/results.xml', params={'filter': 'job:%s' % self.job_uid,
'include_tz': 'true'})
r.raise_for_status()
return r.text

Expand Down Expand Up @@ -1222,22 +1223,40 @@ def pytest_addoption(parser):

def pytest_collect_file(path, parent):
if path.ext == ".py":
return StbtCollector(path, parent)
if hasattr(StbtCollector, "from_parent"):
# pytest >v5.4
return StbtCollector.from_parent(parent=parent, fspath=path) # pylint:disable=no-member
else:
# Backwards compat
# https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent
return StbtCollector(path, parent)
else:
return None


class StbtCollector(pytest.File):
# pylint: disable=abstract-method
def collect(self):
with open(self.fspath.strpath) as f:
# We implement our own parsing to avoid import stbt ImportErrors
for n, line in enumerate(f):
m = re.match(r'^def\s+(test_[a-zA-Z0-9_]*)', line)
if m:
yield StbtRemoteTest(self, self.name, m.group(1), n + 1)
if hasattr(StbtRemoteTest, "from_parent"):
# pytest >v5.4
srt = StbtRemoteTest.from_parent( # pylint:disable=no-member
parent=self, filename=self.name,
testname=m.group(1), line_number=n + 1)
else:
# Backwards compat
# https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent
srt = StbtRemoteTest(
self, self.name, m.group(1), n + 1)
yield srt


class StbtRemoteTest(pytest.Item):
# pylint: disable=abstract-method
def __init__(self, parent, filename, testname, line_number):
super(StbtRemoteTest, self).__init__(testname, parent)
self._filename = filename
Expand Down
3 changes: 2 additions & 1 deletion test_stbt_rig.py
Expand Up @@ -208,6 +208,7 @@ def get_results():
@self.app.route('/api/v2/results.xml')
def get_results_xml():
assert flask.request.args['filter'] == 'job:/mynode/6Pfq/167'
assert flask.request.args['include_tz'] == 'true'
return PortalMock.RESULTS_XML

@self.app.route('/api/v2/results/<path:result_id>')
Expand Down Expand Up @@ -276,7 +277,7 @@ def on_run_tests(self, j):
RESULTS_XML = (
'<testsuite disabled="0" errors="0" failures="0" '
'name="test" skipped="0" tests="1" time="3.270815" '
'timestamp="2019-06-12T15:26:35">'
'timestamp="2019-06-12T15:26:35+00:00">'
'<testcase classname="tests/test.py" name="test_my_tests" '
'time="3.270815"/>'
'</testsuite>')
Expand Down

0 comments on commit b6c717b

Please sign in to comment.