Skip to content

Commit c9e5c9f

Browse files
committed
handle exceptions in ssh_test_container fixture
1 parent 55ecb19 commit c9e5c9f

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

tests/conftest.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Pytest configuration"""
22

3+
import logging
34
import shutil
45
from collections.abc import Generator
56
from dataclasses import dataclass
@@ -13,6 +14,7 @@
1314
from cmem_plugin_ssh.execute_commands import ExecuteCommands
1415
from cmem_plugin_ssh.list import ListFiles
1516
from cmem_plugin_ssh.upload import UploadFiles
17+
from docker.errors import APIError
1618
from tests.fixtures import (
1719
SSH_HOSTNAME,
1820
SSH_PASSWORD,
@@ -21,6 +23,8 @@
2123
SSH_USERNAME,
2224
)
2325

26+
logger = logging.getLogger(__name__)
27+
2428

2529
@dataclass
2630
class TestingEnvironment:
@@ -154,11 +158,13 @@ def get_compose_cmd() -> list[str]:
154158
@pytest.fixture(scope="session")
155159
def ssh_test_container() -> Generator[DockerContainer, None, None]:
156160
"""Start the SSH test container before tests and stop it after."""
157-
with (
158-
DockerImage(path=DOCKER_DIR, tag="test-sample:latest") as image,
159-
DockerContainer(str(image))
160-
.with_exposed_ports(22)
161-
.with_volume_mapping(DOCKER_DIR / "volume", "/home/testuser/volume", "rw") as container,
162-
):
163-
container.start()
164-
yield container
161+
try:
162+
with (
163+
DockerImage(path=DOCKER_DIR, tag="cmem-plugin-openssh:latest", clean_up=False) as image,
164+
DockerContainer(str(image))
165+
.with_exposed_ports(22)
166+
.with_volume_mapping(DOCKER_DIR / "volume", "/home/testuser/volume", "rw") as container,
167+
):
168+
yield container
169+
except APIError:
170+
logger.exception("Failed to cleanup Docker container")

0 commit comments

Comments
 (0)