Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Klement Sekera | fcbf444 | 2017-08-17 07:38:42 +0200 | [diff] [blame] | 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import unittest |
| 6 | import importlib |
| 7 | import argparse |
| 8 | |
| 9 | |
Saima Yunus | c7f93b3 | 2022-08-10 03:25:31 -0400 | [diff] [blame] | 10 | def discover_tests(directory, callback): |
Klement Sekera | fcbf444 | 2017-08-17 07:38:42 +0200 | [diff] [blame] | 11 | do_insert = True |
| 12 | for _f in os.listdir(directory): |
| 13 | f = "%s/%s" % (directory, _f) |
| 14 | if os.path.isdir(f): |
Saima Yunus | c7f93b3 | 2022-08-10 03:25:31 -0400 | [diff] [blame] | 15 | discover_tests(f, callback) |
Klement Sekera | fcbf444 | 2017-08-17 07:38:42 +0200 | [diff] [blame] | 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 Sekera | fcbf444 | 2017-08-17 07:38:42 +0200 | [diff] [blame] | 25 | 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 Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 31 | if name == "VppTestCase" or name.startswith("Template"): |
Klement Sekera | fcbf444 | 2017-08-17 07:38:42 +0200 | [diff] [blame] | 32 | 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 | |
| 40 | def print_callback(file_name, cls, method): |
| 41 | print("%s.%s.%s" % (file_name, cls.__name__, method)) |