File tree Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Original file line number Diff line number Diff line change 77
88
99def 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 ()])
10+ if "func" in metafunc .fixturenames :
11+ targets = []
12+ ids = []
1213
14+ for example_dir in EXAMPLE_DIR .glob ("*" ):
15+ if not example_dir .is_dir ():
16+ continue
1317
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_" ))
18+ for test_file in example_dir .glob ("test*.py" ):
19+ test_module = importlib .import_module (
20+ test_file .relative_to (PROJECT_DIR ).with_suffix ("" ).as_posix ().replace ("/" , "." )
21+ )
22+ test_functions = inspect .getmembers (
23+ test_module ,
24+ lambda x : inspect .isfunction (x ) and x .__name__ .startswith ("test_" ),
25+ )
1726
18- for _name , func in test_functions :
19- func ()
27+ for name , func in test_functions :
28+ targets .append (func )
29+ ids .append (f"{ test_file .relative_to (EXAMPLE_DIR ).with_suffix ('' ).as_posix ()} /{ name } " )
30+
31+ metafunc .parametrize ("func" , targets , ids = ids )
32+
33+
34+ def test_example (func ):
35+ func ()
You can’t perform that action at this time.
0 commit comments