tests: make tests less make dependent
[vpp.git] / test / discover_tests.py
index 99016e2..7f05c31 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import sys
 import os
@@ -7,12 +7,14 @@ import importlib
 import argparse
 
 
-def discover_tests(directory, callback):
+def discover_tests(directory, callback, ignore_path):
     do_insert = True
     for _f in os.listdir(directory):
         f = "%s/%s" % (directory, _f)
         if os.path.isdir(f):
-            discover_tests(f, callback)
+            if ignore_path is not None and f.startswith(ignore_path):
+                continue
+            discover_tests(f, callback, ignore_path)
             continue
         if not os.path.isfile(f):
             continue
@@ -22,8 +24,6 @@ def discover_tests(directory, callback):
         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):
@@ -41,17 +41,3 @@ def discover_tests(directory, callback):
 
 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)