Skip to content

Commit 5d1a9a1

Browse files
authored
invoke unittest directly instead of through the setup.py file (#299)
1 parent 01d3eb0 commit 5d1a9a1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

colcon_core/task/python/test/setuppy_test.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,40 @@
1010

1111

1212
class SetuppyPythonTestingStep(PythonTestingStepExtensionPoint):
13-
"""Use `setup.py test` to test packages."""
13+
"""Use `unittest` to test packages."""
1414

1515
def __init__(self): # noqa: D107
1616
super().__init__()
1717
satisfies_version(
1818
PythonTestingStepExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')
1919

20+
def add_arguments(self, *, parser): # noqa: D102
21+
parser.add_argument(
22+
'--unittest-args',
23+
nargs='*', metavar='*', type=str.lstrip,
24+
help='Pass arguments to Python unittests. '
25+
'Arguments matching other options must be prefixed by a space,\n'
26+
'e.g. --unittest-args " --help"')
27+
2028
def match(self, context, env, setup_py_data): # noqa: D102
2129
return True
2230

2331
async def step(self, context, env, setup_py_data): # noqa: D102
2432
if context.args.retest_until_fail:
2533
logger.warning(
2634
"Ignored '--retest-until-fail' for package "
27-
"'{context.pkg.name}' since 'setup.py test' does not support "
28-
'the usage'.format_map(locals()))
35+
"'{context.pkg.name}' since 'unittest' does not support the "
36+
'usage'.format_map(locals()))
2937

3038
if context.args.retest_until_pass:
3139
logger.warning(
3240
"Ignored '--retest-until-pass' for package "
33-
"'{context.pkg.name}' since 'setup.py test' does not support "
34-
'the usage'.format_map(locals()))
35-
36-
cmd = [
37-
executable,
38-
'setup.py', 'test',
39-
'egg_info', '--egg-base', context.args.build_base,
40-
]
41+
"'{context.pkg.name}' since 'unittest' does not support the "
42+
'usage'.format_map(locals()))
43+
44+
cmd = [executable, '-m', 'unittest', '-v']
45+
if context.args.unittest_args is not None:
46+
cmd += context.args.unittest_args
4147
rc = await check_call(context, cmd, cwd=context.args.path, env=env)
4248
if rc and rc.returncode:
4349
return rc.returncode

0 commit comments

Comments
 (0)