Skip to content

Commit

Permalink
added some test properties
Browse files Browse the repository at this point in the history
  • Loading branch information
javierggt committed Jun 12, 2020
1 parent 37da47e commit 936d030
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions testr/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import collections
import junit_xml
import json
import datetime
import platform

opt = None
logger = None
Expand Down Expand Up @@ -215,14 +217,15 @@ def run_tests(package, tests):
cmd = './' + test['file']
else:
cmd = interpreter + ' ' + test['file']

test['t_start'] = datetime.datetime.now().strftime('%Y:%m:%dT%H:%M:%S')
try:
bash(cmd, logfile=logfile, env=env)
except ShellError:
# Test process returned a non-zero status => Fail
test['status'] = 'FAIL'
else:
test['status'] = 'pass'
test['t_stop'] = datetime.datetime.now().strftime('%Y:%m:%dT%H:%M:%S')

box_output(['{} Test Summary'.format(package)] +
['{:20s} {}'.format(test['file'], test['status']) for test in tests])
Expand Down Expand Up @@ -362,10 +365,18 @@ def _parse_xml(filename):


def write_log(tests, formats=['json', 'xml'], include_stdout=False):
import datetime
now = datetime.datetime.now().strftime('%Y:%m:%dT%H:%M:%S')
all_test_suites = []

uname = platform.uname()
architecture, _ = platform.architecture()
sys_info = {
'system': uname.system,
'architecture': architecture,
'hostname': uname.node,
'platform': platform.platform(True, True)
}

for package in sorted(tests):
pkg_test_suites = []
orphan_tests = []
Expand All @@ -379,10 +390,12 @@ def write_log(tests, formats=['json', 'xml'], include_stdout=False):

xml_file = os.path.join(test['out_dir'], f'{test["file"]}.xml')
if os.path.exists(xml_file):
properties.test.copy()
properties.update(sys_info)
test_suites = _parse_xml(xml_file)
for ts in test_suites:
ts['name'] = f"{package}-{ts['name']}"
ts['properties'] = test.copy()
ts['properties'] = properties
ts['log'] = f"{test['file']}.log"
if len(test_suites) == 1:
test_suites[0]['stdout'] = stdout
Expand Down Expand Up @@ -412,6 +425,7 @@ def write_log(tests, formats=['json', 'xml'], include_stdout=False):
'package': package,
'version': test['package_version'],
}
properties.update(sys_info)
test_suite = dict(
name=f"{package}-tests",
package=package,
Expand Down

0 comments on commit 936d030

Please sign in to comment.