Skip to content

Commit

Permalink
Testing: Export cratedb_service fixture as pytest11 entrypoint
Browse files Browse the repository at this point in the history
This way, for basic needs, corresponding boilerplate code does not need
to be provided by downstream projects.

When needing more configurability, you will need to define corresponding
alternative fixtures, and not use the built-in provided from.
  • Loading branch information
amotl committed Feb 9, 2024
1 parent 3a8e9bf commit 97cff40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion cratedb_toolkit/testing/testcontainers/cratedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import logging
import os
from typing import Optional
from typing import Generator, Optional

Check warning on line 19 in cratedb_toolkit/testing/testcontainers/cratedb.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/testcontainers/cratedb.py#L19

Added line #L19 was not covered by tests

import pytest

Check warning on line 21 in cratedb_toolkit/testing/testcontainers/cratedb.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/testcontainers/cratedb.py#L21

Added line #L21 was not covered by tests
from testcontainers.core.config import MAX_TRIES
from testcontainers.core.generic import DbContainer
from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs
Expand Down Expand Up @@ -212,3 +213,14 @@ def http_url(self):
Used to stay backward compatible with the downstream code.
"""
return self.get_http_url()


@pytest.fixture(scope="session")
def cratedb_service() -> Generator[CrateDBTestAdapter, None, None]:

Check warning on line 219 in cratedb_toolkit/testing/testcontainers/cratedb.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/testcontainers/cratedb.py#L218-L219

Added lines #L218 - L219 were not covered by tests
"""
Provide a CrateDB service instance to the test suite.
"""
db = CrateDBTestAdapter()
db.start()
yield db
db.stop()

Check warning on line 226 in cratedb_toolkit/testing/testcontainers/cratedb.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/testcontainers/cratedb.py#L223-L226

Added lines #L223 - L226 were not covered by tests
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ test = [
testing = [
"testcontainers<4",
]

[project.urls]
changelog = "https://github.com/crate-workbench/cratedb-toolkit/blob/main/CHANGES.rst"
documentation = "https://github.com/crate-workbench/cratedb-toolkit"
Expand All @@ -155,6 +154,8 @@ cratedb-retention = "cratedb_toolkit.retention.cli:cli"
cratedb-toolkit = "cratedb_toolkit.cli:cli"
ctk = "cratedb_toolkit.cli:cli"
migr8 = "cratedb_toolkit.io.mongodb.cli:main"
[project.entry-points.pytest11]
cratedb_service = "cratedb_toolkit.testing.testcontainers.cratedb"

[tool.black]
line-length = 120
Expand Down

0 comments on commit 97cff40

Please sign in to comment.