diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63f3f5d4..8b565e36 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -75,7 +75,7 @@ jobs: - name: Test cibuildwheel run: | - python ./bin/run_tests.py + python ./bin/run_tests.py --run-podman test-emulated: name: Test emulated cibuildwheel using qemu diff --git a/bin/run_tests.py b/bin/run_tests.py index 44c6d302..5f3a3606 100755 --- a/bin/run_tests.py +++ b/bin/run_tests.py @@ -1,33 +1,43 @@ #!/usr/bin/env python3 +import argparse import os import subprocess import sys from pathlib import Path if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--run-podman", action="store_true", default=False, help="run podman tests") + args = parser.parse_args() + # move cwd to the project root os.chdir(Path(__file__).resolve().parents[1]) - # run the unit tests + # unit tests unit_test_args = [sys.executable, "-m", "pytest", "unit_test"] - # run the docker unit tests only on Linux + if sys.platform.startswith("linux"): + # run the docker unit tests only on Linux unit_test_args += ["--run-docker"] + if args.run_podman: + unit_test_args += ["--run-podman"] + subprocess.run(unit_test_args, check=True) - # run the integration tests - subprocess.run( - [ - sys.executable, - "-m", - "pytest", - "--numprocesses=2", - "-x", - "--durations", - "0", - "--timeout=2400", - "test", - ], - check=True, - ) + # integration tests + integration_test_args = [ + sys.executable, + "-m", + "pytest", + "--numprocesses=2", + "-x", + "--durations", + "0", + "--timeout=2400", + "test", + ] + if args.run_podman: + integration_test_args += ["--run-podman"] + + subprocess.run(integration_test_args, check=True) diff --git a/test/conftest.py b/test/conftest.py index d8ff2f62..e7c42112 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -7,20 +7,7 @@ def pytest_addoption(parser) -> None: parser.addoption( "--run-emulation", action="store_true", default=False, help="run emulation tests" ) - - -def pytest_configure(config): - config.addinivalue_line("markers", "emulation: mark test requiring qemu binfmt_misc to run") - - -def pytest_collection_modifyitems(config, items) -> None: - if config.getoption("--run-emulation"): - # --run-emulation given in cli: do not skip emulation tests - return - skip_emulation = pytest.mark.skip(reason="need --run-emulation option to run") - for item in items: - if "emulation" in item.keywords: - item.add_marker(skip_emulation) + parser.addoption("--run-podman", action="store_true", default=False, help="run podman tests") @pytest.fixture( diff --git a/test/test_emulation.py b/test/test_emulation.py index dd76ab36..95b574dd 100644 --- a/test/test_emulation.py +++ b/test/test_emulation.py @@ -17,8 +17,10 @@ def test_spam(): """ -@pytest.mark.emulation -def test(tmp_path): +def test(tmp_path, request): + if not request.config.getoption("--run-emulation"): + pytest.skip("needs --run-emulation option to run") + project_dir = tmp_path / "project" project_with_a_test.generate(project_dir) diff --git a/test/test_podman.py b/test/test_podman.py new file mode 100644 index 00000000..d4bdf556 --- /dev/null +++ b/test/test_podman.py @@ -0,0 +1,37 @@ +import pytest + +from . import test_projects, utils + +basic_project = test_projects.new_c_project() + + +def test(tmp_path, capfd, request): + if utils.platform != "linux": + pytest.skip("the test is only relevant to the linux build") + + if not request.config.getoption("--run-podman"): + pytest.skip("needs --run-podman option to run") + + project_dir = tmp_path / "project" + basic_project.generate(project_dir) + + # build some musllinux and manylinux wheels (ensuring that we use two containers) + actual_wheels = utils.cibuildwheel_run( + project_dir, + add_env={ + "CIBW_BUILD": "cp310-*{manylinux,musllinux}_x86_64", + "CIBW_BEFORE_ALL": "echo 'test log statement from before-all'", + }, + ) + + # check that the expected wheels are produced + expected_wheels = [ + w + for w in utils.expected_wheels("spam", "0.1.0") + if ("-cp310-" in w) and ("x86_64" in w) and ("manylinux" in w or "musllinux" in w) + ] + assert set(actual_wheels) == set(expected_wheels) + + # check that stdout is bring passed-though from container correctly + captured = capfd.readouterr() + assert "test log statement from before-all" in captured.out