mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-21 22:09:23 +01:00
test-runner: extend -S option
The -S/--sub-tests option allows the user to specify a test file from inside an autotest. Inside this file there may also be many test functions. This option is being extended to allow running a single test function inside a test file. For example: * Runs all test functions inside connection_test.py * ./test-runner -A some_test -S connection_test * Runs only connection_test.py test_connect_success() * ./test-runner -A some_test -S connection_test.test_connect_success
This commit is contained in:
parent
42fe6c5a15
commit
fd43a3938f
@ -1139,6 +1139,13 @@ def start_test(ctx, subtests, rqueue):
|
||||
|
||||
# Iterating through each python test file
|
||||
for test in subtest:
|
||||
limit_funcs = []
|
||||
|
||||
if ctx.args.sub_tests:
|
||||
for i in ctx.args.sub_tests:
|
||||
if len(i.split('.')) == 2:
|
||||
limit_funcs.append(i.split('.')[1])
|
||||
|
||||
# Iterating through individual test functions inside a
|
||||
# Test() class. Due to the nature of unittest we have
|
||||
# to jump through some hoops to set up the test class
|
||||
@ -1164,21 +1171,29 @@ def start_test(ctx, subtests, rqueue):
|
||||
result = TestResult()
|
||||
|
||||
try:
|
||||
skip = len(limit_funcs) > 0 and func not in limit_funcs
|
||||
|
||||
# Set up class only on first test
|
||||
if index == 0:
|
||||
dbg("%s\n\t%s RUNNING" % (file, str(func)), end='')
|
||||
if not skip:
|
||||
dbg("%s\n\t%s RUNNING" % (file, str(func)), end='')
|
||||
t.setUpClass()
|
||||
else:
|
||||
dbg("\t%s RUNNING" % str(func), end='')
|
||||
if not skip:
|
||||
dbg("\t%s RUNNING" % str(func), end='')
|
||||
|
||||
sys.__stdout__.flush()
|
||||
|
||||
# Run test (setUp/tearDown run automatically)
|
||||
result = t()
|
||||
if not skip:
|
||||
# Run test (setUp/tearDown run automatically)
|
||||
result = t()
|
||||
|
||||
# Tear down class only on last test
|
||||
if index == len(tlist) - 1:
|
||||
t.tearDownClass()
|
||||
|
||||
if skip:
|
||||
continue
|
||||
except unittest.SkipTest as e:
|
||||
result.skipped.append(t)
|
||||
except Exception as e:
|
||||
@ -1256,9 +1271,13 @@ def pre_test(ctx, test, copied):
|
||||
pruned = []
|
||||
|
||||
for s in subtests:
|
||||
# Allow test name both with and without the extension
|
||||
if s in ctx.args.sub_tests or os.path.splitext(s)[0] in ctx.args.sub_tests:
|
||||
pruned.append(s)
|
||||
file = s
|
||||
# Handle <file>.<test function> format
|
||||
if '.' in s:
|
||||
file = s.split('.')[0] + '.py'
|
||||
|
||||
if file == s:
|
||||
pruned.append(file)
|
||||
|
||||
subtests = pruned
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user