Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions ros2_batch_job/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
# limitations under the License.

import argparse
import configparser
import os
from pathlib import Path
import platform
from shutil import which
import subprocess
Expand Down Expand Up @@ -356,39 +354,6 @@ def build_and_test(args, job):

print('# BEGIN SUBSECTION: test')

# In Foxy and prior, xunit2 format is needed to make Jenkins xunit plugin 2.x happy
# After Foxy, we introduced per-package changes to make local builds and CI
# builds act the same.
if args.ros_distro in ('dashing', 'eloquent', 'foxy'):
# 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 that doesn't choose junit_family=xunit2
# and patch configuration if needed to force the xunit2 value
pytest_6_or_greater = job.run([
'"%s"' % job.python, '-c', "'"
'from distutils.version import StrictVersion;'
'import pytest;'
'import sys;'
'sys.exit(StrictVersion(pytest.__version__) >= StrictVersion("6.0.0"))'
"'"],
exit_on_error=False)
for path in Path('.').rglob('pytest.ini'):
config = configparser.ConfigParser()
config.read(str(path))
if pytest_6_or_greater:
# only need to correct explicit legacy option if exists
if not check_xunit2_junit_family_value(config, 'legacy'):
continue
else:
# in pytest < 6 need to enforce xunit2 if not set
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)

test_cmd = [
args.colcon_script, 'test',
'--base-paths', '"%s"' % args.sourcespace,
Expand All @@ -401,6 +366,19 @@ def build_and_test(args, job):
test_cmd.append('--pytest-with-coverage')
test_cmd.extend(args.test_args)

# In Foxy and prior, xunit2 format is needed to make Jenkins xunit plugin 2.x happy
# After Foxy, we introduced per-package changes to make local builds and CI
# builds act the same.
if args.ros_distro in ('dashing', 'eloquent', 'foxy'):
pytest_args = ['-o', 'junit_family=xunit2']
# We should only have one --pytest-args option, or some options might get ignored
if '--pytest-args' in test_cmd:
pytest_opts_index = test_cmd.index('--pytest-args') + 1
test_cmd = test_cmd[:pytest_opts_index] + pytest_args + test_cmd[pytest_opts_index:]
else:
test_cmd.append('--pytest-args')
test_cmd.extend(pytest_args)

ret_test = job.run(test_cmd, exit_on_error=False, shell=True)
info("colcon test returned: '{0}'".format(ret_test))
print('# END SUBSECTION')
Expand Down Expand Up @@ -432,10 +410,6 @@ 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