diff --git a/tests/containers/conftest.py b/tests/containers/conftest.py index 860bb57149..e5ade7ebbe 100644 --- a/tests/containers/conftest.py +++ b/tests/containers/conftest.py @@ -59,7 +59,13 @@ def pytest_addoption(parser: Parser) -> None: # https://docs.pytest.org/en/latest/reference/reference.html#pytest.hookspec.pytest_generate_tests def pytest_generate_tests(metafunc: Metafunc) -> None: if image.__name__ in metafunc.fixturenames: - metafunc.parametrize(image.__name__, metafunc.config.getoption("--image")) + # scope="session" is required here to match the fixture's declared scope. + # Without it, metafunc.parametrize defaults to function scope and silently + # overrides the fixture scope (https://github.com/pytest-dev/pytest/issues/634), + # causing ScopeMismatch for any session-scoped fixture that depends on `image`. + image_option = metafunc.config.getoption("--image") + assert image_option is not None, "--image option must be provided" + metafunc.parametrize(image.__name__, image_option, scope="session") def get_image_metadata(image: str) -> Image: @@ -125,6 +131,24 @@ def image(request): yield request.param +@pytest.fixture(scope="session") +def container_arch(image: str) -> str: + """Detect the CPU architecture of the container image. Runs once per session.""" + container = testcontainers.core.container.DockerContainer(image=image, user=0) + container.with_command("/bin/sh -c 'sleep infinity'") + known_architectures = {"x86_64", "aarch64", "s390x", "ppc64le"} + try: + container.start() + exit_code, output = container.exec(["uname", "-m"]) + assert exit_code == 0, f"uname -m failed: {output}" + arch = output.decode().strip() + if arch not in known_architectures: + raise ValueError(f"Unexpected architecture {arch!r}, expected one of {known_architectures}") + return arch + finally: + docker_utils.NotebookContainer(container).stop(timeout=0) + + @pytest.fixture(scope="function") def runtime_image(image: str): image_metadata = get_image_metadata(image) diff --git a/tests/containers/workbenches/jupyterlab/jupyterlab_test.py b/tests/containers/workbenches/jupyterlab/jupyterlab_test.py index 8d43af2dda..9637048a8e 100644 --- a/tests/containers/workbenches/jupyterlab/jupyterlab_test.py +++ b/tests/containers/workbenches/jupyterlab/jupyterlab_test.py @@ -56,16 +56,10 @@ def test_spinner_html_loaded(self, jupyterlab_image: conftest.Image) -> None: @allure.issue("RHOAIENG-16568") @allure.description("Check that PDF export is working correctly") - def test_pdf_export(self, jupyterlab_image: conftest.Image) -> None: + def test_pdf_export(self, jupyterlab_image: conftest.Image, container_arch: str) -> None: + if container_arch in ("s390x", "ppc64le"): + pytest.skip(f"PDF export not supported on {container_arch} architecture") container = WorkbenchContainer(image=jupyterlab_image.name, user=4321, group_add=[0]) - # Skip if we're running on s390x architecture - container.start(wait_for_readiness=False) - try: - exit_code, arch_output = container.exec(["uname", "-m"]) - if exit_code == 0 and arch_output.decode().strip() == "s390x": - pytest.skip("PDF export functionality is not supported on s390x architecture") - finally: - docker_utils.NotebookContainer(container).stop(timeout=0) test_file_name = "test.ipybn" test_file_content = """{ "cells": [