2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 341b03ab authored by di68kap's avatar di68kap
Browse files

- DHParser/testing.py: runner now also accepts "test_XXX()"-functions as unit tests

parent f84a5344
......@@ -369,12 +369,16 @@ def grammar_suite(directory, parser_factory, transformer_factory,
return ''
def runner(tests, namespace):
def runner(test_classes, namespace):
Runs all or some selected Python unit tests found in the
namespace. To run all tests in a module, call
``runner("", globals())`` from within that module.
Unit-Tests are either classes, the name of which starts with
"Test" and methods, the name of which starts with "test" contained
in such classes or functions, the name of which starts with "test".
tests: Either a string or a list of strings that contains the
names of test or test classes. Each test and, in the case
......@@ -403,18 +407,23 @@ def runner(tests, namespace):
return obj
if tests:
if isinstance(tests, str):
tests = tests.split(" ")
if test_classes:
if isinstance(test_classes, str):
test_classes = test_classes.split(" ")
# collect all test classes, in case no methods or classes have been passed explicitly
tests = []
test_classes = []
test_functions = []
for name in namespace.keys():
if name.lower().startswith('test') and inspect.isclass(namespace[name]):
if name.lower().startswith('test'):
if inspect.isclass(namespace[name]):
elif inspect.isfunction(namespace[name]):
obj = None
for test in tests:
for test in test_classes:
if test.find('.') >= 0:
cls_name, method_name = test.split('.')
......@@ -430,3 +439,7 @@ def runner(tests, namespace):
if "teardown" in dir(obj):
for test in test_functions:
exec(test + '()', namespace)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment