11from __future__ import annotations
22
33import binascii
4+ import contextlib
45import inspect
56import json
67import logging
1112import textwrap
1213from typing import TYPE_CHECKING , Any
1314
15+ import allure
1416import pytest
1517import testcontainers .core .container
1618
2022LOGGER = logging .getLogger (__name__ )
2123
2224if TYPE_CHECKING :
23- from collections .abc import Callable
25+ from collections .abc import Callable , Generator
2426
2527 import pytest_subtests
2628
@@ -43,6 +45,23 @@ def _run_test(self, image: str, test_fn: Callable[[testcontainers.core.container
4345 # If the return doesn't happen in the try block, fail the test
4446 pytest .fail ("The test did not pass as expected." )
4547
48+ @contextlib .contextmanager
49+ def _test_container (self , image : str ) -> Generator [testcontainers .core .container .DockerContainer ]:
50+ """Context manager that starts a test container and yields it."""
51+ container = testcontainers .core .container .DockerContainer (image = image , user = 23456 , group_add = [0 ])
52+ container .with_command ("/bin/sh -c 'sleep infinity'" )
53+ try :
54+ container .start ()
55+ yield container
56+ return
57+ except Exception as e :
58+ pytest .fail (f"Unexpected exception in test: { e } " )
59+ finally :
60+ docker_utils .NotebookContainer (container ).stop (timeout = 0 )
61+
62+ # If the return doesn't happen in the try block, fail the test
63+ pytest .fail ("The test did not pass as expected." )
64+
4665 def test_elf_files_can_link_runtime_libs (self , subtests : pytest_subtests .SubTests , image ):
4766 def test_fn (container : testcontainers .core .container .DockerContainer ):
4867 def check_elf_file ():
@@ -250,6 +269,28 @@ def test_fn(container: testcontainers.core.container.DockerContainer):
250269
251270 self ._run_test (image = image , test_fn = test_fn )
252271
272+ @allure .issue ("RHAIENG-2189" )
273+ def test_python_package_index (self , image : str , subtests : pytest_subtests .SubTests ):
274+ """Checks that we use the Python Package Index we mean to use.
275+ https://redhat-internal.slack.com/archives/C05TTTYG599/p1764240587118899?thread_ts=1764234802.564119&cid=C05TTTYG599
276+ """
277+
278+ expected_env = {
279+ "PIP_EXTRA_INDEX_URL" : "https://pypi.org/simple" ,
280+ "UV_EXTRA_INDEX_URL" : "https://pypi.org/simple" ,
281+ }
282+
283+ with self ._test_container (image = image ) as container :
284+ _ , output = container .exec (["env" ])
285+ output = output .decode ().strip ()
286+
287+ actual = {}
288+ for line in output .splitlines ():
289+ key , value = line .split ("=" , maxsplit = 1 )
290+ actual [key ] = value
291+
292+ assert actual .items () >= expected_env .items ()
293+
253294
254295def encode_python_function_execution_command_interpreter (
255296 python : str , function : Callable [..., Any ], * args : list [Any ]
0 commit comments