forked from fgmacedo/python-statemachine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_examples.py
More file actions
32 lines (22 loc) · 804 Bytes
/
Copy pathtest_examples.py
File metadata and controls
32 lines (22 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pathlib import Path
import pytest
from .helpers import import_module_by_path
def pytest_generate_tests(metafunc):
if "example_file_wrapper" not in metafunc.fixturenames:
return
file_names = [
pytest.param(example_path, id=f"{example_path}")
for example_path in Path("tests/examples").glob("**/*_machine.py")
]
metafunc.parametrize("file_name", file_names)
@pytest.fixture()
def example_file_wrapper(file_name):
def execute_file_wrapper():
module = import_module_by_path(file_name.with_suffix(""))
main = getattr(module, "main", None)
if main:
main()
return execute_file_wrapper
def test_example(example_file_wrapper):
"""Import the example file so the module is executed"""
example_file_wrapper()