diff options
author | Sachin Saxena <sachin.saxena@freescale.com> | 2018-02-28 20:28:52 +0530 |
---|---|---|
committer | Sachin Saxena <sachin.saxena@nxp.com> | 2018-02-28 20:34:56 +0530 |
commit | 0689fce93ba269c48f83a2f70f971b3976d04c90 (patch) | |
tree | 4cc2908df3598507cc1828ac19d8c43b22450ffa /test/discover_tests.py | |
parent | 746b57564deede624261ab8a96c94f562f24d22c (diff) | |
parent | d594711a5d79859a7d0bde83a516f7ab52051d9b (diff) |
Merge branch 'stable/1710' of https://gerrit.fd.io/r/vpp into 17101710
Diffstat (limited to 'test/discover_tests.py')
-rwxr-xr-x | test/discover_tests.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/discover_tests.py b/test/discover_tests.py new file mode 100755 index 00000000..eea59410 --- /dev/null +++ b/test/discover_tests.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import sys +import os +import unittest +import importlib +import argparse + + +def discover_tests(directory, callback): + do_insert = True + for _f in os.listdir(directory): + f = "%s/%s" % (directory, _f) + if os.path.isdir(f): + discover_tests(f, callback) + continue + if not os.path.isfile(f): + continue + if do_insert: + sys.path.insert(0, directory) + do_insert = False + if not _f.startswith("test_") or not _f.endswith(".py"): + continue + name = "".join(f.split("/")[-1].split(".")[:-1]) + if name in sys.modules: + raise Exception("Duplicate test module `%s' found!" % name) + module = importlib.import_module(name) + for name, cls in module.__dict__.items(): + if not isinstance(cls, type): + continue + if not issubclass(cls, unittest.TestCase): + continue + if name == "VppTestCase": + continue + for method in dir(cls): + if not callable(getattr(cls, method)): + continue + if method.startswith("test_"): + callback(_f, cls, method) + + +def print_callback(file_name, cls, method): + print("%s.%s.%s" % (file_name, cls.__name__, method)) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Discover VPP unit tests") + parser.add_argument("-d", "--dir", action='append', type=str, + help="directory containing test files " + "(may be specified multiple times)") + args = parser.parse_args() + if args.dir is None: + args.dir = "." + + suite = unittest.TestSuite() + for d in args.dir: + discover_tests(d, print_callback) |