Skip to content
29 changes: 21 additions & 8 deletions ros2_batch_job/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,27 @@ 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
# check if packages have a pytest.ini file that doesn't choose junit_family=xunit2
# and patch configuration if needed to force the xunit2 value
xunit_6_or_greater = job.run([
Comment thread
j-rivero marked this conversation as resolved.
Outdated
'"%s"' % job.python, '-c', '\''
Comment thread
j-rivero marked this conversation as resolved.
Outdated
'from distutils.version import StrictVersion;'
'import pytest;'
'import sys;'
'sys.exit(StrictVersion(pytest.__version__) >= StrictVersion("6.0.0"))'
'\''])
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':
if xunit_6_or_greater:
Comment thread
j-rivero marked this conversation as resolved.
Outdated
# only need to correct explicit legacy option if exists
if not check_xunit2_junit_family_value(config, 'legacy'):
continue
except configparser.NoOptionError:
pass
print('xunit2 patch applied to ' + str(path))
else:
# in xunit < 6 need to enforce xunit2 if not set
Comment thread
j-rivero marked this conversation as resolved.
Outdated
if check_xunit2_junit_family_value(config, 'xunit2'):
continue
print("Patch '%s' to override 'pytest.junit_family=xunit2'" % path)
config.set('pytest', 'junit_family', 'xunit2')
with open(path, 'w+') as configfile:
config.write(configfile)
Expand Down Expand Up @@ -443,6 +452,10 @@ def build_and_test(args, job):
return 0


def check_xunit2_junit_family_value(config, value):
return config.get('pytest', 'junit_family', fallback='') == value


def run(args, build_function, blacklisted_package_names=None):
if blacklisted_package_names is None:
blacklisted_package_names = []
Expand Down