From 224bba52d3dd4a02b67494da908744f9a5201a51 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Fri, 9 Feb 2024 23:22:21 +0100 Subject: [PATCH] Testing: Use unique names when running multiple test container instances --- cratedb_toolkit/testing/testcontainers/cratedb.py | 8 +++++--- tests/conftest.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cratedb_toolkit/testing/testcontainers/cratedb.py b/cratedb_toolkit/testing/testcontainers/cratedb.py index 183bac03..7c793389 100644 --- a/cratedb_toolkit/testing/testcontainers/cratedb.py +++ b/cratedb_toolkit/testing/testcontainers/cratedb.py @@ -71,6 +71,7 @@ def __init__( password: Optional[str] = None, dbname: Optional[str] = None, cmd_opts: Optional[dict] = None, + name: Optional[str] = None, **kwargs, ) -> None: """ @@ -89,7 +90,7 @@ def __init__( """ super().__init__(image=image, **kwargs) - self._name = "testcontainers-cratedb" + self._name = name or "testcontainers-cratedb" cmd_opts = cmd_opts or {} self._command = self._build_cmd({**self.CMD_OPTS, **cmd_opts}) @@ -162,16 +163,17 @@ class CrateDBTestAdapter: CrateDB Toolkit's `DatabaseAdapter`, agnostic of the test framework. """ - def __init__(self, crate_version: str = "nightly", **kwargs): + def __init__(self, crate_version: str = "nightly", name: str = None, **kwargs): self.cratedb: Optional[CrateDBContainer] = None self.database: Optional[DatabaseAdapter] = None self.image: str = "crate/crate:{}".format(crate_version) + self.name = name def start(self, **kwargs): """ Start testcontainer, used for tests set up """ - self.cratedb = CrateDBContainer(image=self.image, **kwargs) + self.cratedb = CrateDBContainer(image=self.image, name=self.name, **kwargs) self.cratedb.start() self.database = DatabaseAdapter(dburi=self.get_connection_url()) diff --git a/tests/conftest.py b/tests/conftest.py index 637e1529..b8376062 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -59,7 +59,7 @@ def cratedb_service(): """ Provide a CrateDB service instance to the test suite. """ - db = CrateDBTestAdapter() + db = CrateDBTestAdapter(name="testcontainers-cratedb-custom") db.start(ports={CRATEDB_HTTP_PORT: None}, cmd_opts=CRATEDB_SETTINGS) db.reset(tables=RESET_TABLES) yield db