|
14 | 14 |
|
15 | 15 | from cibuildwheel.environment import EnvironmentAssignmentBash |
16 | 16 | from cibuildwheel.oci_container import OCIContainer, OCIContainerEngineConfig |
| 17 | +from cibuildwheel.util import detect_ci_provider |
17 | 18 |
|
18 | 19 | # Test utilities |
19 | 20 |
|
|
31 | 32 | PODMAN = OCIContainerEngineConfig(name="podman") |
32 | 33 |
|
33 | 34 |
|
34 | | -@pytest.fixture(params=["docker", "podman"]) |
| 35 | +@pytest.fixture(params=["docker", "podman"], scope="module") |
35 | 36 | def container_engine(request): |
36 | 37 | if request.param == "docker" and not request.config.getoption("--run-docker"): |
37 | 38 | pytest.skip("need --run-docker option to run") |
38 | 39 | if request.param == "podman" and not request.config.getoption("--run-podman"): |
39 | 40 | pytest.skip("need --run-podman option to run") |
40 | | - return OCIContainerEngineConfig(name=request.param) |
| 41 | + |
| 42 | + def get_images() -> set[str]: |
| 43 | + if detect_ci_provider() is None: |
| 44 | + return set() |
| 45 | + images = subprocess.run( |
| 46 | + [request.param, "image", "ls", "--format", "{{json .ID}}"], |
| 47 | + text=True, |
| 48 | + check=True, |
| 49 | + stdout=subprocess.PIPE, |
| 50 | + ).stdout |
| 51 | + return {json.loads(image.strip()) for image in images.splitlines() if image.strip()} |
| 52 | + |
| 53 | + images_before = get_images() |
| 54 | + try: |
| 55 | + yield OCIContainerEngineConfig(name=request.param) |
| 56 | + finally: |
| 57 | + images_after = get_images() |
| 58 | + for image in images_after - images_before: |
| 59 | + subprocess.run([request.param, "rmi", image], check=False) |
41 | 60 |
|
42 | 61 |
|
43 | 62 | # Tests |
@@ -230,10 +249,9 @@ def test_environment_executor(container_engine): |
230 | 249 | assert assignment.evaluated_value({}, container.environment_executor) == "42" |
231 | 250 |
|
232 | 251 |
|
233 | | -def test_podman_vfs(tmp_path: Path, monkeypatch, request): |
234 | | - # Tests podman VFS, for the podman in docker use-case |
235 | | - if not request.config.getoption("--run-podman"): |
236 | | - pytest.skip("need --run-podman option to run") |
| 252 | +def test_podman_vfs(tmp_path: Path, monkeypatch, container_engine): |
| 253 | + if container_engine.name != "podman": |
| 254 | + pytest.skip("only runs with podman") |
237 | 255 |
|
238 | 256 | # create the VFS configuration |
239 | 257 | vfs_path = tmp_path / "podman_vfs" |
@@ -309,9 +327,9 @@ def test_podman_vfs(tmp_path: Path, monkeypatch, request): |
309 | 327 | subprocess.run(["podman", "unshare", "rm", "-rf", vfs_path], check=True) |
310 | 328 |
|
311 | 329 |
|
312 | | -def test_create_args_volume(tmp_path: Path, request): |
313 | | - if not request.config.getoption("--run-docker"): |
314 | | - pytest.skip("need --run-docker option to run") |
| 330 | +def test_create_args_volume(tmp_path: Path, container_engine): |
| 331 | + if container_engine.name != "docker": |
| 332 | + pytest.skip("only runs with docker") |
315 | 333 |
|
316 | 334 | if "CIRCLECI" in os.environ or "GITLAB_CI" in os.environ: |
317 | 335 | pytest.skip( |
|
0 commit comments