blob: fbd2d9c7e59b77f64b93410c8893231a9d5f0408 [file] [log] [blame]
Klement Sekerafcbf4442017-08-17 07:38:42 +02001#!/usr/bin/env python
2
3import sys
4import os
5import unittest
6import importlib
7import argparse
8
9
10def discover_tests(directory, callback):
11 do_insert = True
12 for _f in os.listdir(directory):
13 f = "%s/%s" % (directory, _f)
14 if os.path.isdir(f):
15 discover_tests(f, callback)
16 continue
17 if not os.path.isfile(f):
18 continue
19 if do_insert:
20 sys.path.insert(0, directory)
21 do_insert = False
22 if not _f.startswith("test_") or not _f.endswith(".py"):
23 continue
24 name = "".join(f.split("/")[-1].split(".")[:-1])
Klement Sekerafcbf4442017-08-17 07:38:42 +020025 module = importlib.import_module(name)
26 for name, cls in module.__dict__.items():
27 if not isinstance(cls, type):
28 continue
29 if not issubclass(cls, unittest.TestCase):
30 continue
Klement Sekera31da2e32018-06-24 22:49:55 +020031 if name == "VppTestCase" or name.startswith("Template"):
Klement Sekerafcbf4442017-08-17 07:38:42 +020032 continue
33 for method in dir(cls):
34 if not callable(getattr(cls, method)):
35 continue
36 if method.startswith("test_"):
37 callback(_f, cls, method)
38
39
40def print_callback(file_name, cls, method):
41 print("%s.%s.%s" % (file_name, cls.__name__, method))
42
43
44if __name__ == '__main__':
45 parser = argparse.ArgumentParser(description="Discover VPP unit tests")
46 parser.add_argument("-d", "--dir", action='append', type=str,
47 help="directory containing test files "
48 "(may be specified multiple times)")
49 args = parser.parse_args()
50 if args.dir is None:
51 args.dir = "."
52
53 suite = unittest.TestSuite()
54 for d in args.dir:
55 discover_tests(d, print_callback)