blob: 7f05c3184ff02e79b2adddcefaf72c930922409b [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Klement Sekerafcbf4442017-08-17 07:38:42 +02002
3import sys
4import os
5import unittest
6import importlib
7import argparse
8
9
Klement Sekerab8c72a42018-11-08 11:21:39 +010010def discover_tests(directory, callback, ignore_path):
Klement Sekerafcbf4442017-08-17 07:38:42 +020011 do_insert = True
12 for _f in os.listdir(directory):
13 f = "%s/%s" % (directory, _f)
14 if os.path.isdir(f):
Klement Sekerab8c72a42018-11-08 11:21:39 +010015 if ignore_path is not None and f.startswith(ignore_path):
16 continue
17 discover_tests(f, callback, ignore_path)
Klement Sekerafcbf4442017-08-17 07:38:42 +020018 continue
19 if not os.path.isfile(f):
20 continue
21 if do_insert:
22 sys.path.insert(0, directory)
23 do_insert = False
24 if not _f.startswith("test_") or not _f.endswith(".py"):
25 continue
26 name = "".join(f.split("/")[-1].split(".")[:-1])
Klement Sekerafcbf4442017-08-17 07:38:42 +020027 module = importlib.import_module(name)
28 for name, cls in module.__dict__.items():
29 if not isinstance(cls, type):
30 continue
31 if not issubclass(cls, unittest.TestCase):
32 continue
Klement Sekera31da2e32018-06-24 22:49:55 +020033 if name == "VppTestCase" or name.startswith("Template"):
Klement Sekerafcbf4442017-08-17 07:38:42 +020034 continue
35 for method in dir(cls):
36 if not callable(getattr(cls, method)):
37 continue
38 if method.startswith("test_"):
39 callback(_f, cls, method)
40
41
42def print_callback(file_name, cls, method):
43 print("%s.%s.%s" % (file_name, cls.__name__, method))