From 06fd2aa309a585e3d61c4ada92bd93b32bd8782e Mon Sep 17 00:00:00 2001 From: David Ankin Date: Mon, 22 Sep 2025 08:35:24 -0400 Subject: [PATCH 1/3] fix(core): make sure context manager exits --- core/testcontainers/compose/compose.py | 9 +++++++-- core/testcontainers/core/container.py | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/testcontainers/compose/compose.py b/core/testcontainers/compose/compose.py index 9441010d..7605adfa 100644 --- a/core/testcontainers/compose/compose.py +++ b/core/testcontainers/compose/compose.py @@ -1,3 +1,4 @@ +import sys from dataclasses import asdict, dataclass, field, fields, is_dataclass from functools import cached_property from json import loads @@ -223,8 +224,12 @@ def __post_init__(self) -> None: self.env_file = [self.env_file] def __enter__(self) -> "DockerCompose": - self.start() - return self + try: + self.start() + return self + except: # noqa: E722, RUF100 + self.__exit__(*sys.exc_info()) + raise def __exit__( self, exc_type: Optional[type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index dc5470c3..f0882a4c 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -1,4 +1,5 @@ import contextlib +import sys from os import PathLike from socket import socket from types import TracebackType @@ -215,7 +216,11 @@ def stop(self, force: bool = True, delete_volume: bool = True) -> None: self.get_docker_client().client.close() def __enter__(self) -> Self: - return self.start() + try: + return self.start() + except: # noqa: E722, RUF100 + self.__exit__(*sys.exc_info()) + raise def __exit__( self, exc_type: Optional[type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] From 944b3386f2cc14f70182cfa55bbafa5b8276c970 Mon Sep 17 00:00:00 2001 From: David Ankin Date: Mon, 22 Sep 2025 08:41:25 -0400 Subject: [PATCH 2/3] pyproject schema changed --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 6a14968b..bc6bba76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ maintainers = [ ] readme = "README.md" keywords = ["testing", "logging", "docker", "test automation"] +license = "Apache-2.0" classifiers = [ "License :: OSI Approved :: Apache Software License", "Intended Audience :: Information Technology", From 8653d2f50f3c1cc8a3e6a308abda1d6db46ed0cc Mon Sep 17 00:00:00 2001 From: David Ankin Date: Mon, 22 Sep 2025 08:55:06 -0400 Subject: [PATCH 3/3] running into all python changes today --- .github/workflows/ci-core.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core.yml b/.github/workflows/ci-core.yml index 53122c50..fa8fbce9 100644 --- a/.github/workflows/ci-core.yml +++ b/.github/workflows/ci-core.yml @@ -24,7 +24,7 @@ jobs: - name: Install Python dependencies run: poetry install --all-extras - name: Run twine check - run: poetry build && poetry run twine check dist/*.tar.gz + run: rm -f LICENSE.txt && poetry build && poetry run twine check dist/*.tar.gz - name: Set up Docker uses: docker/setup-docker-action@v4 - name: Run tests