test: add sources_module fixture for sources unit tests
Similar to the `stage_module` fixture for stage tests this adds a fixture to test sources modules of osbuild. The code from `stage_module` and `sources_module` is similar and could be combined but pytest makes it hard to do this without having a shared root dir. Given that it's just four lines it seems easier to just life with the tiny bit of code duplication.
This commit is contained in:
parent
6572b1b8e7
commit
119172e8dd
2 changed files with 22 additions and 1 deletions
21
sources/test/conftest.py
Normal file
21
sources/test/conftest.py
Normal file
|
|
@ -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))
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -25,7 +25,7 @@ deps =
|
||||||
tox-backticks
|
tox-backticks
|
||||||
|
|
||||||
setenv =
|
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 = osbuild
|
||||||
TYPEABLES_STRICT = ./osbuild/main_cli.py
|
TYPEABLES_STRICT = ./osbuild/main_cli.py
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue