From dfe2011ceef2272b3c179ceb7229d85d70ba5a1b Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Tue, 9 Jun 2026 11:12:39 +0200 Subject: [PATCH] test: skip example satisfiability checks on unsupported platforms --- .../test_examples_satisfiability.py | 63 +++++++++++++++---- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/tests/integration_python/pixi_build/test_examples_satisfiability.py b/tests/integration_python/pixi_build/test_examples_satisfiability.py index 7b60f4e0c5..c2e212091e 100644 --- a/tests/integration_python/pixi_build/test_examples_satisfiability.py +++ b/tests/integration_python/pixi_build/test_examples_satisfiability.py @@ -1,9 +1,32 @@ import tomllib from pathlib import Path +from typing import TypeAlias, cast import pytest -from .common import repo_root, verify_cli_command +from .common import current_platform, repo_root, verify_cli_command + +Workspace: TypeAlias = dict[str, object] + + +def workspace_from_manifest(manifest_path: Path) -> Workspace | None: + manifest = cast(dict[str, object], tomllib.loads(manifest_path.read_text())) + if manifest_path.name == "pyproject.toml": + # Only consider pyproject.toml files that configure a pixi workspace + # to avoid testing non-pixi files. + tool = cast(dict[str, object], manifest.get("tool", {})) + pixi = cast(dict[str, object], tool.get("pixi", {})) + workspace = pixi.get("workspace") + elif manifest_path.name == "pixi.toml": + # Only consider pixi.toml files with a workspace section to avoid + # testing non-workspace member manifests. + workspace = manifest.get("workspace") + else: + return None + + if isinstance(workspace, dict): + return cast(Workspace, workspace) + return None def workspace_example_manifests() -> list[Path]: @@ -14,18 +37,7 @@ def workspace_example_manifests() -> list[Path]: """ manifests: list[Path] = [] for manifest_path in sorted(repo_root().joinpath("examples").glob("**/p*.toml")): - manifest = tomllib.loads(manifest_path.read_text()) - if manifest_path.name == "pyproject.toml": - # Only consider pyproject.toml files that configure a pixi workspace - # to avoid testing non-pixi files. - workspace = manifest.get("tool", {}).get("pixi", {}).get("workspace") - elif manifest_path.name == "pixi.toml": - # Only consider pixi.toml files with a workspace section to avoid - # testing non-workspace member manifests. - workspace = manifest.get("workspace") - else: - continue - if workspace is not None: + if workspace_from_manifest(manifest_path) is not None: manifests.append(manifest_path) return manifests @@ -33,6 +45,24 @@ def workspace_example_manifests() -> list[Path]: WORKSPACE_EXAMPLE_MANIFESTS = workspace_example_manifests() +def supports_current_platform(workspace: Workspace) -> bool: + """Return whether the workspace supports the current runner platform.""" + platforms = workspace.get("platforms") + if not isinstance(platforms, list): + return False + + current = current_platform() + for platform in cast(list[object], platforms): + if platform == current: + return True + if isinstance(platform, dict): + rich_platform = cast(dict[str, object], platform) + if rich_platform.get("name") == current or rich_platform.get("platform") == current: + return True + + return False + + @pytest.mark.slow @pytest.mark.parametrize( "manifest_path", @@ -47,6 +77,13 @@ def test_example_lock_file_satisfiability(pixi: Path, manifest_path: Path) -> No `PIXI_BUILD_BACKEND_OVERRIDE` that is set by the session fixture in `conftest.py`. """ + workspace = workspace_from_manifest(manifest_path) + if workspace is None: + pytest.fail(f"{manifest_path} does not contain a pixi workspace") + + if not supports_current_platform(workspace): + pytest.skip(f"example does not support current platform {current_platform()}") + verify_cli_command( [ pixi,