Skip to content

Commit 5f4de22

Browse files
committed
test(pytest): parameterized examples tests
1 parent 2bad99f commit 5f4de22

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tests/test_examples.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
def test_simple_service():
2-
from examples.simple_service import test
1+
import importlib
2+
import inspect
3+
from pathlib import Path
34

4-
test.test_main()
5+
PROJECT_DIR = Path(__file__).parent.parent
6+
EXAMPLE_DIR = PROJECT_DIR / "examples"
7+
8+
9+
def pytest_generate_tests(metafunc):
10+
if "example_name" in metafunc.fixturenames:
11+
metafunc.parametrize("example_name", [item.name for item in EXAMPLE_DIR.glob("*") if item.is_dir()])
12+
13+
14+
def test_example(example_name: str):
15+
test_module = importlib.import_module(f"examples.{example_name}.test")
16+
test_functions = inspect.getmembers(test_module, lambda x: inspect.isfunction(x) and x.__name__.startswith("test_"))
17+
18+
for _name, func in test_functions:
19+
func()

0 commit comments

Comments
 (0)