Skip to content

Commit 7344630

Browse files
[rhoai-2.25] RHAIENG-6036: skip PDF export on s390x and ppc64le via container_arch (#2497)
Backport the container_arch fixture approach from main (opendatahub-io#3472) instead of starting a throwaway container inside test_pdf_export. PDF export is not supported on these architectures; the skip is not a CI flake workaround. (cherry picked from commit 3e4958b) Co-authored-by: Cursor <cursoragent@cursor.com> * RHAIENG-6036: fix(tests): session-scope image parametrization for container_arch Session-scoped container_arch depends on image; metafunc.parametrize must pass scope="session" or pytest raises ScopeMismatch (pytest #634). * RHAIENG-6036: chore(tests): add message to --image assert guard Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ba8d7dd commit 7344630

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

tests/containers/conftest.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ def pytest_addoption(parser: Parser) -> None:
5959
# https://docs.pytest.org/en/latest/reference/reference.html#pytest.hookspec.pytest_generate_tests
6060
def pytest_generate_tests(metafunc: Metafunc) -> None:
6161
if image.__name__ in metafunc.fixturenames:
62-
metafunc.parametrize(image.__name__, metafunc.config.getoption("--image"))
62+
# scope="session" is required here to match the fixture's declared scope.
63+
# Without it, metafunc.parametrize defaults to function scope and silently
64+
# overrides the fixture scope (https://github.com/pytest-dev/pytest/issues/634),
65+
# causing ScopeMismatch for any session-scoped fixture that depends on `image`.
66+
image_option = metafunc.config.getoption("--image")
67+
assert image_option is not None, "--image option must be provided"
68+
metafunc.parametrize(image.__name__, image_option, scope="session")
6369

6470

6571
def get_image_metadata(image: str) -> Image:
@@ -125,6 +131,24 @@ def image(request):
125131
yield request.param
126132

127133

134+
@pytest.fixture(scope="session")
135+
def container_arch(image: str) -> str:
136+
"""Detect the CPU architecture of the container image. Runs once per session."""
137+
container = testcontainers.core.container.DockerContainer(image=image, user=0)
138+
container.with_command("/bin/sh -c 'sleep infinity'")
139+
known_architectures = {"x86_64", "aarch64", "s390x", "ppc64le"}
140+
try:
141+
container.start()
142+
exit_code, output = container.exec(["uname", "-m"])
143+
assert exit_code == 0, f"uname -m failed: {output}"
144+
arch = output.decode().strip()
145+
if arch not in known_architectures:
146+
raise ValueError(f"Unexpected architecture {arch!r}, expected one of {known_architectures}")
147+
return arch
148+
finally:
149+
docker_utils.NotebookContainer(container).stop(timeout=0)
150+
151+
128152
@pytest.fixture(scope="function")
129153
def runtime_image(image: str):
130154
image_metadata = get_image_metadata(image)

tests/containers/workbenches/jupyterlab/jupyterlab_test.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,10 @@ def test_spinner_html_loaded(self, jupyterlab_image: conftest.Image) -> None:
5656

5757
@allure.issue("RHOAIENG-16568")
5858
@allure.description("Check that PDF export is working correctly")
59-
def test_pdf_export(self, jupyterlab_image: conftest.Image) -> None:
59+
def test_pdf_export(self, jupyterlab_image: conftest.Image, container_arch: str) -> None:
60+
if container_arch in ("s390x", "ppc64le"):
61+
pytest.skip(f"PDF export not supported on {container_arch} architecture")
6062
container = WorkbenchContainer(image=jupyterlab_image.name, user=4321, group_add=[0])
61-
# Skip if we're running on s390x architecture
62-
container.start(wait_for_readiness=False)
63-
try:
64-
exit_code, arch_output = container.exec(["uname", "-m"])
65-
if exit_code == 0 and arch_output.decode().strip() == "s390x":
66-
pytest.skip("PDF export functionality is not supported on s390x architecture")
67-
finally:
68-
docker_utils.NotebookContainer(container).stop(timeout=0)
6963
test_file_name = "test.ipybn"
7064
test_file_content = """{
7165
"cells": [

0 commit comments

Comments
 (0)