Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: Export cratedb_service fixture as pytest11 entrypoint #113

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.idea
.venv*
*.egg-info
.eggs
__pycache__
.env
.idea
*.pyc
.venv*
__pycache__
dist
.coverage*
coverage.xml
/tmp
16 changes: 16 additions & 0 deletions cratedb_toolkit/testing/pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Generator

Check warning on line 1 in cratedb_toolkit/testing/pytest.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/pytest.py#L1

Added line #L1 was not covered by tests

import pytest

Check warning on line 3 in cratedb_toolkit/testing/pytest.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/pytest.py#L3

Added line #L3 was not covered by tests

from cratedb_toolkit.testing.testcontainers.cratedb import CrateDBTestAdapter

Check warning on line 5 in cratedb_toolkit/testing/pytest.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/pytest.py#L5

Added line #L5 was not covered by tests


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

Check warning on line 9 in cratedb_toolkit/testing/pytest.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/pytest.py#L8-L9

Added lines #L8 - L9 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 16 in cratedb_toolkit/testing/pytest.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/pytest.py#L13-L16

Added lines #L13 - L16 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.pytest"

[tool.black]
line-length = 120
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def configure_database_schema(session_mocker, prune_environment):


@pytest.fixture(scope="session")
def cratedb_service():
def cratedb_custom_service():
"""
Provide a CrateDB service instance to the test suite.
"""
Expand All @@ -67,12 +67,12 @@ def cratedb_service():


@pytest.fixture(scope="function")
def cratedb(cratedb_service):
def cratedb(cratedb_custom_service):
"""
Provide a fresh canvas to each test case invocation, by resetting database content.
"""
cratedb_service.reset(tables=RESET_TABLES)
yield cratedb_service
cratedb_custom_service.reset(tables=RESET_TABLES)
yield cratedb_custom_service


@pytest.fixture
Expand Down
16 changes: 16 additions & 0 deletions tests/testing/test_pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re

import pytest


@pytest.mark.skip("Does not work, because something stalls when using multiple containers")
def test_cratedb_service(cratedb_service):
"""
Verify the exported pytest fixture `cratedb_service` works as intended.
"""
assert re.match(r"http://crate:@localhost:\d\d\d\d\d", cratedb_service.get_http_url())
assert re.match(r"crate://crate:@localhost:\d\d\d\d\d", cratedb_service.get_connection_url())

sql = "SELECT mountain FROM sys.summits ORDER BY prominence DESC LIMIT 1;"
highest_summit = cratedb_service.database.run_sql(sql, records=True)[0]
assert highest_summit["mountain"] == "Mont Blanc"
Loading