3030class TestBaseImage :
3131 """Tests that are applicable for all images we have in this repository."""
3232
33- def _run_test (self , image : str , test_fn : Callable [[testcontainers .core .container .DockerContainer ], None ]):
34- container = testcontainers .core .container .DockerContainer (image = image , user = 23456 , group_add = [0 ])
35- container .with_command ("/bin/sh -c 'sleep infinity'" )
36- try :
37- container .start ()
33+ def _run_test (self , image : str , test_fn : Callable [[testcontainers .core .container .DockerContainer ], None ]) -> None :
34+ with self ._test_container (image ) as container :
3835 test_fn (container )
39- return
40- except Exception as e :
41- pytest .fail (f"Unexpected exception in test: { e } " )
42- finally :
43- docker_utils .NotebookContainer (container ).stop (timeout = 0 )
44-
45- # If the return doesn't happen in the try block, fail the test
46- pytest .fail ("The test did not pass as expected." )
4736
4837 @contextlib .contextmanager
4938 def _test_container (self , image : str ) -> Generator [testcontainers .core .container .DockerContainer ]:
@@ -59,8 +48,7 @@ def _test_container(self, image: str) -> Generator[testcontainers.core.container
5948 finally :
6049 docker_utils .NotebookContainer (container ).stop (timeout = 0 )
6150
62- # If the return doesn't happen in the try block, fail the test
63- pytest .fail ("The test did not pass as expected." )
51+ raise RuntimeError ("Cannot happen: the test did not pass as expected." )
6452
6553 def test_elf_files_can_link_runtime_libs (self , subtests : pytest_subtests .SubTests , image ):
6654 def test_fn (container : testcontainers .core .container .DockerContainer ):
0 commit comments