tests: Clean up test case importing
Move this to a helper function and return a set of test names instead of a list. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
3054112254
commit
91282e29ff
1 changed files with 19 additions and 17 deletions
|
@ -228,28 +228,30 @@ def get_test_description(t):
|
||||||
desc += " [long]"
|
desc += " [long]"
|
||||||
return desc
|
return desc
|
||||||
|
|
||||||
def main():
|
def import_test_cases():
|
||||||
tests = []
|
tests = []
|
||||||
test_modules = []
|
test_modules = []
|
||||||
names = set()
|
names = set()
|
||||||
files = os.listdir(scriptsdir)
|
files = os.listdir(scriptsdir)
|
||||||
for t in files:
|
re_files = (re.match(r'(test_.*)\.py$', n) for n in files)
|
||||||
m = re.match(r'(test_.*)\.py$', t)
|
test_files = (m.group(1) for m in re_files if m)
|
||||||
if m:
|
for t in test_files:
|
||||||
logger.debug("Import test cases from " + t)
|
mod = __import__(t)
|
||||||
mod = __import__(m.group(1))
|
test_modules.append(mod.__name__.replace('test_', '', 1))
|
||||||
test_modules.append(mod.__name__.replace('test_', '', 1))
|
for key, val in mod.__dict__.items():
|
||||||
for key, val in mod.__dict__.items():
|
if key.startswith("test_"):
|
||||||
if key.startswith("test_"):
|
if val.__doc__ is None:
|
||||||
if val.__doc__ is None:
|
print(f"Test case {val.__name__} misses __doc__")
|
||||||
print(f"Test case {val.__name__} misses __doc__")
|
tests.append(val)
|
||||||
tests.append(val)
|
|
||||||
|
|
||||||
name = val.__name__.replace('test_', '', 1)
|
name = val.__name__.replace('test_', '', 1)
|
||||||
if name in names:
|
if name in names:
|
||||||
print(f"Test case {name} defined multiple times")
|
print(f"Test case {name} defined multiple times")
|
||||||
names.add(name)
|
names.add(name)
|
||||||
test_names = list(names)
|
return tests, test_modules, names
|
||||||
|
|
||||||
|
def main():
|
||||||
|
tests, test_modules, test_names = import_test_cases()
|
||||||
|
|
||||||
run = None
|
run = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue