blob: 0eaa149d0db2fd41cffbaa414756c813c18aa980 [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
Saima Yunusc7f93b32022-08-10 03:25:31 -040010def discover_tests(directory, callback):
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):
Saima Yunusc7f93b32022-08-10 03:25:31 -040015 discover_tests(f, callback)
Klement Sekerafcbf4442017-08-17 07:38:42 +020016 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))