From 209f9f39bfc7a17cfdbb7b55a44ff7f56e821681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Mon, 17 Apr 2023 17:33:51 +0200 Subject: [PATCH 2/3] Test: add ability to skip tests for unsupported file-systems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- test/conftest.py | 19 +++++++++++++++++++ test/run/test_assemblers.py | 14 ++++++-------- test/test.py | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 test/conftest.py diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..f2ff9f3 --- /dev/null +++ b/test/conftest.py @@ -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") diff --git a/test/run/test_assemblers.py b/test/run/test_assemblers.py index 30638e6..8783866 100644 --- a/test/run/test_assemblers.py +++ b/test/run/test_assemblers.py @@ -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}", diff --git a/test/test.py b/test/test.py index 98be29b..c51548c 100644 --- a/test/test.py +++ b/test/test.py @@ -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 -- 2.39.2