Test: add ability to skip tests for unsupported file-systems

Add a new optional pytest CLI argument `--unsupported-fs` allowing to
specify file-systems which should be treated as unsupported in the
platform where running tests. Any test cases dependent on such
file-system support will be sipped.

This will allow to run unit tests and selectively skipping test cases
for unsupported file-systems.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-04-17 17:33:51 +02:00 committed by Achilleas Koutsou
parent db89984465
commit ff6b96bee5
3 changed files with 39 additions and 8 deletions

19
test/conftest.py Normal file
View file

@ -0,0 +1,19 @@
unsupported_filesystems = []
"""Globally accessible list of filesystems that are unsupported on the system when running test cases"""
def pytest_addoption(parser):
parser.addoption(
"--unsupported-fs",
action="append",
default=[],
metavar="FS",
help="List of filesystems to treat as unsupported on the system when running test cases." +
"Can be specified multiple times.",
)
def pytest_configure(config):
# pylint: disable=global-statement
global unsupported_filesystems
unsupported_filesystems = config.getoption("--unsupported-fs")

View file

@ -81,6 +81,8 @@ def read_partition_table(device):
@pytest.mark.skipif(not test.TestBase.can_bind_mount(), reason="root-only")
@pytest.mark.parametrize("fs_type", ["ext4", "xfs", "btrfs"])
def test_rawfs(osbuild, fs_type):
if not test.TestBase.has_filesystem_support(fs_type):
pytest.skip(f"The {fs_type} was explicitly marked as unsupported on this platform.")
options = {
"filename": "image.raw",
"root_fs_uuid": "016a1cda-5182-4ab3-bf97-426b00b74eb0",
@ -150,17 +152,13 @@ def test_ostree(osbuild):
@pytest.mark.skipif(not test.TestBase.have_tree_diff(), reason="tree-diff missing")
@pytest.mark.skipif(not test.TestBase.have_test_data(), reason="no test-data access")
@pytest.mark.skipif(not test.TestBase.can_bind_mount(), reason="root-only")
@pytest.mark.parametrize(
"fmt,fs_type",
[("raw", "ext4"), ("raw", "xfs"), ("raw", "btrfs"),
("raw.xz", "ext4"), ("raw.xz", "xfs"), ("raw.xz", "btrfs"),
("qcow2", "ext4"), ("qcow2", "xfs"), ("qcow2", "btrfs"),
("vmdk", "ext4"), ("vmdk", "xfs"), ("vmdk", "btrfs"),
("vdi", "ext4"), ("vdi", "xfs"), ("vdi", "btrfs")]
)
@pytest.mark.parametrize("fmt,", ["raw", "raw.xz", "qcow2", "vmdk", "vdi"])
@pytest.mark.parametrize("fs_type", ["ext4", "xfs", "btrfs"])
def test_qemu(osbuild, fmt, fs_type):
loctl = loop.LoopControl()
with osbuild as osb:
if not test.TestBase.has_filesystem_support(fs_type):
pytest.skip(f"The {fs_type} was explicitly marked as unsupported on this platform.")
options = {
"format": fmt,
"filename": f"image.{fmt}",

View file

@ -15,6 +15,8 @@ import osbuild.meta
from osbuild.objectstore import ObjectStore
from osbuild.util import linux
from .conftest import unsupported_filesystems
class TestBase(unittest.TestCase):
"""Base Class for Tests
@ -263,6 +265,18 @@ class TestBase(unittest.TestCase):
output = subprocess.check_output([os.path.join(checkout, "tools/tree-diff"), path1, path2])
return json.loads(output)
@staticmethod
def has_filesystem_support(fs: str) -> bool:
"""Check File-System Support
Check whether the current test-run has support for the given file-system.
The assumption is that any file-system is treated as supported, unless
explicitly marked as unsupported when executing pytest. This allows us
to skip tests for file-systems that are not supported on specific
platforms.
"""
return fs not in unsupported_filesystems
class OSBuild(contextlib.AbstractContextManager):
"""OSBuild Executor