mounts: add mounts_module_fixture to allow testing mount modules
Similar to `stages` and `sources` we need some basic infrastructure so that we can use a `mounts_module` fixture for the coming tests to the mount modules.
This commit is contained in:
parent
f26e62b23f
commit
d504165c80
2 changed files with 34 additions and 1 deletions
33
mounts/test/conftest.py
Normal file
33
mounts/test/conftest.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import os
|
||||
import pathlib
|
||||
from types import ModuleType
|
||||
|
||||
import pytest
|
||||
|
||||
from osbuild import mounts, testutil
|
||||
from osbuild.testutil.imports import import_module_from_path
|
||||
|
||||
|
||||
@pytest.fixture(name="mounts_module")
|
||||
def mounts_module_fixture(request: pytest.FixtureRequest) -> ModuleType:
|
||||
"""mounts_module is a fixture that imports a stage module by its name
|
||||
defined in MOUNTS_NAME in the test module.
|
||||
"""
|
||||
if not hasattr(request.module, "MOUNTS_NAME"):
|
||||
raise ValueError("mounts_module fixture must be used in a test module that defines MOUNTS_NAME")
|
||||
|
||||
mounts_name = request.module.MOUNTS_NAME
|
||||
caller_dir = pathlib.Path(request.node.fspath).parent
|
||||
module_path = caller_dir.parent / mounts_name
|
||||
return import_module_from_path("mounts", os.fspath(module_path))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mounts_service(mounts_module) -> ModuleType:
|
||||
"""mounts_service is a fixture that imports a mounts module by its name
|
||||
defined in MOUNTS_NAME in the test module and returns a MountsService
|
||||
"""
|
||||
service_cls = testutil.find_one_subclass_in_module(mounts_module, mounts.MountService)
|
||||
fd = testutil.make_fake_service_fd()
|
||||
srv_obj = service_cls.from_args(["--service-fd", str(fd)])
|
||||
return srv_obj
|
||||
2
tox.ini
2
tox.ini
|
|
@ -24,7 +24,7 @@ deps =
|
|||
requests
|
||||
|
||||
setenv =
|
||||
LINTABLES = osbuild/ assemblers/* devices/* inputs/*.* mounts/* runners/* sources/*.* stages/*.* inputs/test/*.py stages/test/*.py sources/test/*.py test/ tools/
|
||||
LINTABLES = osbuild/ assemblers/* devices/* inputs/*.* mounts/*.* mounts/test/*.py runners/* sources/*.* stages/*.* inputs/test/*.py stages/test/*.py sources/test/*.py test/ tools/
|
||||
LINTABLES_EXCLUDES = "*.json,*.sh"
|
||||
LINTABLES_EXCLUDES_RE = ".*\.json$,.*\.sh"
|
||||
TYPEABLES = osbuild
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue