-
Notifications
You must be signed in to change notification settings - Fork 36
Force xunit2 for pytest 6.0 when legacy mode is enabled #415
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 3 commits
66c4b35
5d11513
057c1f7
d0cf651
bce4422
4e70a79
95c94f1
5072cf4
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 |
|---|---|---|
|
|
@@ -14,9 +14,11 @@ | |
|
|
||
| import argparse | ||
| import configparser | ||
| from distutils.version import StrictVersion | ||
| import os | ||
| from pathlib import Path | ||
| import platform | ||
| import pytest | ||
| from shutil import which | ||
| import subprocess | ||
| import sys | ||
|
|
@@ -333,6 +335,35 @@ def process_coverage(args, job): | |
| return 0 | ||
|
|
||
|
|
||
| def check_xunit2_junit_family_value(config, value): | ||
| try: | ||
| if config.get('pytest', 'junit_family') == value: | ||
| return True | ||
| except configparser.NoOptionError: | ||
| return False | ||
| else: | ||
| return False | ||
|
|
||
|
|
||
| def force_xunit2_in_pytest_ini_files(): | ||
| xunit_6_or_greater = StrictVersion(pytest.__version__) >= StrictVersion('6.0.0') | ||
| for path in Path('.').rglob('pytest.ini'): | ||
| config = configparser.ConfigParser() | ||
| config.read(str(path)) | ||
| if xunit_6_or_greater: | ||
| # only need to correct explicit legacy option if exists | ||
| if not check_xunit2_junit_family_value(config, 'legacy'): | ||
| continue | ||
| else: | ||
| # in xunit < 6 need to enforce xunit2 if not set | ||
| if check_xunit2_junit_family_value(config, 'xunit2'): | ||
| continue | ||
|
Member
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 am wondering if the duplicate logic in the
Author
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. the code was awful, yes. I made some changes in 057c1f7 . Hopefully it can be read more easily. |
||
| print('xunit2 patch applied to ' + str(path)) | ||
|
dirk-thomas marked this conversation as resolved.
Outdated
|
||
| config.set('pytest', 'junit_family', 'xunit2') | ||
| with open(path, 'w+') as configfile: | ||
| config.write(configfile) | ||
|
|
||
|
|
||
| def build_and_test(args, job): | ||
| compile_with_clang = args.compile_with_clang and args.os == 'linux' | ||
|
|
||
|
|
@@ -382,21 +413,9 @@ def build_and_test(args, job): | |
| # xunit2 format is needed to make Jenkins xunit plugin 2.x happy | ||
| with open('pytest.ini', 'w') as ini_file: | ||
| ini_file.write('[pytest]\njunit_family=xunit2') | ||
| # check if packages have a pytest.ini file and add the xunit2 | ||
| # format if it is not present | ||
| for path in Path('.').rglob('pytest.ini'): | ||
| config = configparser.ConfigParser() | ||
| config.read(str(path)) | ||
| try: | ||
| # only if xunit2 is set continue the loop with the file unpatched | ||
| if config.get('pytest', 'junit_family') == 'xunit2': | ||
| continue | ||
| except configparser.NoOptionError: | ||
| pass | ||
| print('xunit2 patch applied to ' + str(path)) | ||
| config.set('pytest', 'junit_family', 'xunit2') | ||
| with open(path, 'w+') as configfile: | ||
| config.write(configfile) | ||
| # check if packages have a pytest.ini file that will override xunit2 setup | ||
| # and patch configuration if needed to keep the xunit2 configuration | ||
| force_xunit2_in_pytest_ini_files() | ||
|
dirk-thomas marked this conversation as resolved.
Outdated
|
||
|
|
||
| test_cmd = [ | ||
| args.colcon_script, 'test', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.