Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion tests/containers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment thread
coderabbitai[bot] marked this conversation as resolved.


def get_image_metadata(image: str) -> Image:
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions tests/containers/workbenches/jupyterlab/jupyterlab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Loading