|
1 | 1 | """Pytest configuration""" |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import shutil |
4 | 5 | from collections.abc import Generator |
5 | 6 | from dataclasses import dataclass |
|
13 | 14 | from cmem_plugin_ssh.execute_commands import ExecuteCommands |
14 | 15 | from cmem_plugin_ssh.list import ListFiles |
15 | 16 | from cmem_plugin_ssh.upload import UploadFiles |
| 17 | +from docker.errors import APIError |
16 | 18 | from tests.fixtures import ( |
17 | 19 | SSH_HOSTNAME, |
18 | 20 | SSH_PASSWORD, |
|
21 | 23 | SSH_USERNAME, |
22 | 24 | ) |
23 | 25 |
|
| 26 | +logger = logging.getLogger(__name__) |
| 27 | + |
24 | 28 |
|
25 | 29 | @dataclass |
26 | 30 | class TestingEnvironment: |
@@ -154,11 +158,13 @@ def get_compose_cmd() -> list[str]: |
154 | 158 | @pytest.fixture(scope="session") |
155 | 159 | def ssh_test_container() -> Generator[DockerContainer, None, None]: |
156 | 160 | """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