Skip to content
Snippets Groups Projects
Commit 99e5ac82 authored by Damian Johnson's avatar Damian Johnson
Browse files

Support multiple '--test' arguments

When supplied our '--test' argument limits us to only running that specific
test. I added this to help with single-test troubleshooting, but on reflection
it could be useful to the network team as well to limit their CI to only run
the tests they're concerned with.

Only gotcha was that we didn't support multiple '--test' arguments. Resolving
that.
parent c2dabe17
No related branches found
No related tags found
No related merge requests found
......@@ -114,49 +114,61 @@ def log_traceback(sig, frame):
os._exit(-1)
def get_unit_tests(module_prefix = None):
def get_unit_tests(module_prefixes = None):
"""
Provides the classes for our unit tests.
:param str module_prefix: only provide the test if the module starts with
this substring
:param list module_prefixes: only provide the test if the module starts with
any of these substrings
:returns: an **iterator** for our unit tests
"""
if module_prefix and not module_prefix.startswith('test.unit.'):
module_prefix = 'test.unit.' + module_prefix
return _get_tests(CONFIG['test.unit_tests'].splitlines(), module_prefixes)
return _get_tests(CONFIG['test.unit_tests'].splitlines(), module_prefix)
def get_integ_tests(module_prefix = None):
def get_integ_tests(module_prefixes = None):
"""
Provides the classes for our integration tests.
:param str module_prefix: only provide the test if the module starts with
this substring
:param list module_prefixes: only provide the test if the module starts with
any of these substrings
:returns: an **iterator** for our integration tests
"""
if module_prefix and not module_prefix.startswith('test.integ.'):
module_prefix = 'test.integ.' + module_prefix
return _get_tests(CONFIG['test.integ_tests'].splitlines(), module_prefix)
return _get_tests(CONFIG['test.integ_tests'].splitlines(), module_prefixes)
def _get_tests(modules, module_prefix):
def _get_tests(modules, module_prefixes):
for import_name in modules:
module, module_name = import_name.rsplit('.', 1) # example: util.conf.TestConf
if not module_prefixes:
yield import_name
else:
# Example import_name: test.unit.util.conf.TestConf
#
# Our '--test' argument doesn't include the prefix, so excluding it from
# the names we look for.
if not module_prefix or module.startswith(module_prefix):
if import_name.startswith('test.unit.'):
cropped_name = import_name[10:]
elif import_name.startswith('test.integ.'):
cropped_name = import_name[11:]
else:
cropped_name = import_name
cropped_name = cropped_name.rsplit('.', 1)[0] # exclude the class name
for prefix in module_prefixes:
if cropped_name.startswith(prefix):
yield import_name
elif module_prefix.startswith(module):
break
elif prefix.startswith(cropped_name):
# single test for this module
test_name = module_prefix.rsplit('.', 1)[1]
test_name = prefix.rsplit('.', 1)[1]
yield '%s.%s' % (import_name, test_name)
break
def main():
......
......@@ -26,7 +26,7 @@ CONFIG = stem.util.conf.config_dict('test', {
DEFAULT_ARGS = {
'run_unit': False,
'run_integ': False,
'specific_test': None,
'specific_test': [],
'logging_runlevel': None,
'tor_path': 'tor',
'run_targets': [test.Target.RUN_OPEN],
......@@ -103,7 +103,7 @@ def parse(argv):
args['attribute_targets'] = attribute_targets
elif opt == '--test':
args['specific_test'] = arg
args['specific_test'].append(arg)
elif opt in ('-l', '--log'):
arg = arg.upper()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment