-
Notifications
You must be signed in to change notification settings - Fork 128
[feat] Extend the JUnit report #3702
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
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 |
|---|---|---|
|
|
@@ -172,6 +172,14 @@ def _do_restore(self, testcase): | |
| f'could not restore testcase {testcase!r}') from e | ||
|
|
||
|
|
||
| def _tail_file(filename, num_lines): | ||
| try: | ||
| with open(filename, encoding='utf-8', errors='replace') as fp: | ||
| return ''.join(fp.readlines()[-num_lines:]) | ||
| except OSError: | ||
| return '' | ||
|
|
||
|
|
||
| def _expand_report_filename(filepatt, *, newfile): | ||
| if '{sessionid}' not in os.fspath(filepatt): | ||
| return filepatt | ||
|
|
@@ -539,7 +547,28 @@ def generate_xml_report(self): | |
| testcase, 'failure', attrib={'type': 'failure', | ||
| 'message': fail_phase} | ||
| ) | ||
| testcase_msg.text = f"{tc['fail_phase']}: {fail_reason}" | ||
| workdir = tc.get('outputdir') or tc.get('stagedir') or '' | ||
| stdout = '' | ||
| stderr = '' | ||
| if workdir: | ||
| job_stdout = tc.get('job_stdout') | ||
| if job_stdout: | ||
| stdout = _tail_file( | ||
| os.path.join(workdir, job_stdout), 20 | ||
| ) | ||
|
|
||
| job_stderr = tc.get('job_stderr') | ||
| if job_stderr: | ||
| stderr = _tail_file( | ||
| os.path.join(workdir, job_stderr), 20 | ||
| ) | ||
|
|
||
| testcase_msg.text = '\n\n'.join([ | ||
| f"{tc['fail_phase']}: {fail_reason}", | ||
| workdir, | ||
| stdout, | ||
| stderr | ||
| ]) | ||
|
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. @toxa81 I'm working right now on extending the JSON report and the last lines of stdout/stderr are now included in case of errors. The idea is that the JUnit report will use this info directly. If I understand correctly you want include the stdout/stderr in the error message, right? I was wondering if there is dedicated field in the JUnit schema for logging stdout/stderr 🤔
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. I think the standard convention is to include it special elements, which is what we should do: https://github.com/testmoapp/junitxml#properties-in-test-output |
||
|
|
||
| testsuite_stdout = etree.SubElement(xml_testsuite, 'system-out') | ||
| testsuite_stdout.text = '' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed: you can use the
osext.tail()function.