blob: dbf23eff12f8788e7dbadde068e57c3ed13c6c46 [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
Klement Sekerafcbf4442017-08-17 07:38:42 +02007
8
Saima Yunusc7f93b32022-08-10 03:25:31 -04009def discover_tests(directory, callback):
Klement Sekerafcbf4442017-08-17 07:38:42 +020010 do_insert = True
11 for _f in os.listdir(directory):
12 f = "%s/%s" % (directory, _f)
13 if os.path.isdir(f):
Saima Yunusc7f93b32022-08-10 03:25:31 -040014 discover_tests(f, callback)
Klement Sekerafcbf4442017-08-17 07:38:42 +020015 continue
16 if not os.path.isfile(f):
17 continue
18 if do_insert:
19 sys.path.insert(0, directory)
20 do_insert = False
21 if not _f.startswith("test_") or not _f.endswith(".py"):
22 continue
23 name = "".join(f.split("/")[-1].split(".")[:-1])
Klement Sekerafcbf4442017-08-17 07:38:42 +020024 module = importlib.import_module(name)
25 for name, cls in module.__dict__.items():
26 if not isinstance(cls, type):
27 continue
28 if not issubclass(cls, unittest.TestCase):
29 continue
Dave Wallace8800f732023-08-31 00:47:44 -040030 if (
31 name == "VppTestCase"
32 or name == "VppAsfTestCase"
33 or name.startswith("Template")
34 ):
Klement Sekerafcbf4442017-08-17 07:38:42 +020035 continue
36 for method in dir(cls):
37 if not callable(getattr(cls, method)):
38 continue
39 if method.startswith("test_"):
40 callback(_f, cls, method)
41
42
43def print_callback(file_name, cls, method):
44 print("%s.%s.%s" % (file_name, cls.__name__, method))