diff --git a/sources/test/conftest.py b/sources/test/conftest.py new file mode 100644 index 00000000..9b9ec2fb --- /dev/null +++ b/sources/test/conftest.py @@ -0,0 +1,21 @@ +import os +import pathlib +from types import ModuleType + +import pytest + +from osbuild.testutil.imports import import_module_from_path + + +@pytest.fixture +def sources_module(request: pytest.FixtureRequest) -> ModuleType: + """sources_module is a fixture that imports a stage module by its name + defined in SOURCES_NAME in the test module. + """ + if not hasattr(request.module, "SOURCES_NAME"): + raise ValueError("sources_module fixture must be used in a test module that defines SOURCES_NAME") + + sources_name = request.module.SOURCES_NAME + caller_dir = pathlib.Path(request.node.fspath).parent + module_path = caller_dir.parent / sources_name + return import_module_from_path("sources", os.fspath(module_path)) diff --git a/tox.ini b/tox.ini index 731d042f..a00e8aa0 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ deps = tox-backticks setenv = - LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*.* stages/test/*.py test/ `find ./tools ! -name "*.sh" -type f` + LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/*.* stages/*.* stages/test/*.py sources/test/*.py test/ `find ./tools ! -name "*.sh" -type f` TYPEABLES = osbuild TYPEABLES_STRICT = ./osbuild/main_cli.py