-
Notifications
You must be signed in to change notification settings - Fork 191
kola-junit: switch python-junit-xml to junitparser #4577
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ import os | |||||||||||||||||||||||
| import re | ||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| from junit_xml import TestSuite, TestCase | ||||||||||||||||||||||||
| from junitparser import TestSuite, TestCase, JUnitXml, Failure, Skipped | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| parser = argparse.ArgumentParser() | ||||||||||||||||||||||||
|
|
@@ -31,6 +31,12 @@ def strip_ansi(text): | |||||||||||||||||||||||
| return ansi_escape.sub('', text) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def strip_control_chars(text): | ||||||||||||||||||||||||
| if text is None: | ||||||||||||||||||||||||
| return text | ||||||||||||||||||||||||
| return re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f]', '', text) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # In a {kola_outputdir}/{testname}/ dir, there can be multiple directories; one | ||||||||||||||||||||||||
| # per host that was brought up. e.g. the Tang test brings up a Tang server in a | ||||||||||||||||||||||||
| # separate host. We can only report one host, so we choose the one whose dir | ||||||||||||||||||||||||
|
|
@@ -89,11 +95,12 @@ for test in report['tests']: | |||||||||||||||||||||||
| # for external tests; we append the kola-runext.service output | ||||||||||||||||||||||||
| if ext_test_out is not None: | ||||||||||||||||||||||||
| test['output'] += f"\n---\n{ext_test_out}" | ||||||||||||||||||||||||
| test['output'] = strip_ansi(test['output']) | ||||||||||||||||||||||||
| test['output'] = strip_control_chars(strip_ansi(test['output'])) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if test['result'] == 'PASS': | ||||||||||||||||||||||||
| tc = TestCase(test['name'], args.classname + ".tests", | ||||||||||||||||||||||||
| test['duration'] / 10**9, test["output"]) | ||||||||||||||||||||||||
| test['duration'] / 10**9) | ||||||||||||||||||||||||
| tc.system_out = test["output"] | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| # we only add console/journal for failing tests | ||||||||||||||||||||||||
| console_txt = None | ||||||||||||||||||||||||
|
|
@@ -102,25 +109,33 @@ for test in report['tests']: | |||||||||||||||||||||||
| console_fn = os.path.join(host_dir, "console.txt") | ||||||||||||||||||||||||
| if os.path.isfile(console_fn): | ||||||||||||||||||||||||
| with open(console_fn, encoding='utf-8') as f: | ||||||||||||||||||||||||
| console_txt = strip_ansi(f.read()) | ||||||||||||||||||||||||
| console_txt = strip_control_chars(strip_ansi(f.read())) | ||||||||||||||||||||||||
| journal_fn = os.path.join(host_dir, "journal.txt") | ||||||||||||||||||||||||
| if os.path.isfile(journal_fn): | ||||||||||||||||||||||||
| with open(journal_fn, encoding='utf-8') as f: | ||||||||||||||||||||||||
| journal_txt = f.read() | ||||||||||||||||||||||||
| journal_txt = strip_control_chars(f.read()) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| tc = TestCase(test['name'], args.classname + ".tests", | ||||||||||||||||||||||||
| test['duration'] / 10**9, console_txt, journal_txt) | ||||||||||||||||||||||||
| test['duration'] / 10**9) | ||||||||||||||||||||||||
| tc.system_out = console_txt | ||||||||||||||||||||||||
| tc.system_err = journal_txt | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if test["result"] == 'FAIL': | ||||||||||||||||||||||||
| tc.add_failure_info(message="Test failed", output=test["output"]) | ||||||||||||||||||||||||
| fail = Failure("Test failed") | ||||||||||||||||||||||||
| fail.text = test["output"] | ||||||||||||||||||||||||
| tc.result = [fail] | ||||||||||||||||||||||||
| elif test["result"] == 'SKIP': | ||||||||||||||||||||||||
| tc.add_skipped_info(message="Test skipped", output=test["output"]) | ||||||||||||||||||||||||
| skip = Skipped("Test skipped") | ||||||||||||||||||||||||
| skip.text = test["output"] | ||||||||||||||||||||||||
| tc.result = [skip] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| test_cases.append(tc) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ts = TestSuite(args.classname, test_cases) | ||||||||||||||||||||||||
| ts = TestSuite(args.classname) | ||||||||||||||||||||||||
| ts.add_testcases(test_cases) | ||||||||||||||||||||||||
| xml = JUnitXml() | ||||||||||||||||||||||||
| xml.add_testsuite(ts) | ||||||||||||||||||||||||
| if args.output == '-': | ||||||||||||||||||||||||
| TestSuite.to_file(sys.stdout, [ts]) | ||||||||||||||||||||||||
| xml.write('/dev/stdout') | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| with open(args.outputxml, "w", encoding='utf-8') as f: | ||||||||||||||||||||||||
| TestSuite.to_file(f, [ts]) | ||||||||||||||||||||||||
| xml.write(args.output) | ||||||||||||||||||||||||
|
Comment on lines
138
to
+141
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Writing to
Suggested change
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.