10 def discover_tests(directory, callback, ignore_path):
12 for _f in os.listdir(directory):
13 f = "%s/%s" % (directory, _f)
15 if ignore_path is not None and f.startswith(ignore_path):
17 discover_tests(f, callback, ignore_path)
19 if not os.path.isfile(f):
22 sys.path.insert(0, directory)
24 if not _f.startswith("test_") or not _f.endswith(".py"):
26 name = "".join(f.split("/")[-1].split(".")[:-1])
27 module = importlib.import_module(name)
28 for name, cls in module.__dict__.items():
29 if not isinstance(cls, type):
31 if not issubclass(cls, unittest.TestCase):
33 if name == "VppTestCase" or name.startswith("Template"):
35 for method in dir(cls):
36 if not callable(getattr(cls, method)):
38 if method.startswith("test_"):
39 callback(_f, cls, method)
42 def print_callback(file_name, cls, method):
43 print("%s.%s.%s" % (file_name, cls.__name__, method))
46 if __name__ == '__main__':
47 parser = argparse.ArgumentParser(description="Discover VPP unit tests")
48 parser.add_argument("-d", "--dir", action='append', type=str,
49 help="directory containing test files "
50 "(may be specified multiple times)")
51 args = parser.parse_args()
55 ignore_path = os.getenv("VENV_PATH", "")
56 suite = unittest.TestSuite()
58 discover_tests(d, print_callback, ignore_path)