Skip to content

Commit 443efa4

Browse files
authored
feat: move Dolt to clientless validation (#125)
## Summary - move Dolt tests to use the bundled container CLI instead of mysql.connector - expose Dolt credential/database fixtures for user overrides - pre-pull the Dolt image in CI so fixture startup does not pull it lazily Includes the stacked PR #129
1 parent 18875e1 commit 443efa4

12 files changed

Lines changed: 336 additions & 272 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@v6
3030

31-
- name: Install additional dependencies
32-
run: sudo apt-get update && sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 libmariadb-dev && sudo apt-get autoremove -y && sudo apt-get clean -y
33-
3431
- name: Set up Python ${{ matrix.python-version }}
3532
uses: actions/setup-python@v6
3633
with:
@@ -52,6 +49,7 @@ jobs:
5249
images=(
5350
"mcr.microsoft.com/azure-storage/azurite"
5451
"mcr.microsoft.com/mssql/server:2022-latest"
52+
"dolthub/dolt-sql-server:latest"
5553
"postgres:11" "postgres:12" "postgres:13" "postgres:14"
5654
"postgres:15" "postgres:16" "postgres:17" "postgres:18"
5755
"pgvector/pgvector:pg15"
@@ -73,8 +71,6 @@ jobs:
7371
"gcr.io/cloud-spanner-emulator/emulator:latest"
7472
"ghcr.io/goccy/bigquery-emulator:latest"
7573
"gizmodata/gizmosql:latest"
76-
"elasticsearch:7.17.19"
77-
"elasticsearch:8.13.0"
7874
)
7975
printf '%s\n' "${images[@]}" | xargs -n1 -P6 -I{} bash -c '
8076
image="$1"
@@ -112,9 +108,6 @@ jobs:
112108
test_elasticsearch:
113109
runs-on: ubuntu-latest
114110
steps:
115-
- name: Install additional dependencies
116-
run: sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 libmariadb-dev
117-
118111
- uses: actions/checkout@v6
119112

120113
- name: Set up Python

.github/workflows/docs.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v6
2424

25-
- name: Install additional dependencies
26-
run: sudo apt-get update && sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 libmariadb-dev && sudo apt-get autoremove -y && sudo apt-get clean -y
27-
2825
- name: Set up Python ${{ matrix.python-version }}
2926
uses: actions/setup-python@v6
3027
with:

.github/workflows/release.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ jobs:
1212
id-token: write
1313
environment: release
1414
steps:
15-
- name: Install additional dependencies
16-
run: sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 libmariadb-dev
17-
1815
- name: Check out repository
1916
uses: actions/checkout@v6
2017

docs/getting-started/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To use ``pytest-databases`` with specific databases, you need to install optiona
2727
* - Oracle
2828
- ``pytest-databases[oracle]``
2929
* - SQL Server
30-
- ``pytest-databases[sqlserver]``
30+
- ``pytest-databases[mssql]``
3131
* - Google AlloyDB Omni
3232
- ``pytest-databases[alloydb]``
3333
* - Google Spanner

docs/supported-databases/dolt.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Dolt is a MySQL-compatible database that provides Git-like versioning for your d
88
Installation
99
------------
1010

11-
Dolt support is built-in and does not require any additional Python client libraries for basic service management. Since Dolt is MySQL-compatible, you can connect to the database from your tests using your preferred MySQL client (e.g., ``mysql-connector-python``).
11+
The fixture provides a running Dolt SQL service and validates availability with the container's bundled tools. Since
12+
Dolt is MySQL-compatible, use the service attributes with the MySQL client, ORM, or application configuration you
13+
normally use.
1214

1315
Usage Example
1416
-------------
@@ -22,7 +24,6 @@ Usage Example
2224
pytest_plugins = ["pytest_databases.docker.dolt"]
2325
2426
def test(dolt_service: DoltService) -> None:
25-
# Create your own connection using the service fixture attributes
2627
with mysql.connector.connect(
2728
host=dolt_service.host,
2829
port=dolt_service.port,
@@ -38,6 +39,10 @@ Available Fixtures
3839
------------------
3940

4041
* ``dolt_service``: A fixture that provides a Dolt service (latest).
42+
* ``dolt_user``: The application user configured in the container.
43+
* ``dolt_password``: The application user password configured in the container.
44+
* ``dolt_root_password``: The root password configured in the container.
45+
* ``dolt_database``: The initial database configured in the container.
4146

4247
Isolation Level
4348
---------------

docs/supported-databases/sqlserver.rst

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,34 @@ Installation
1010
1111
pip install pytest-databases[mssql]
1212
13+
The ``mssql`` extra is kept as a compatibility group. The fixture provides a running SQL Server service and validates
14+
availability with SQL Server's bundled tools. Install the SQL Server client library that your application already uses.
15+
1316
Usage Example
1417
-------------
1518

1619
.. code-block:: python
1720
18-
import pytest
19-
import pymssql
21+
import pyodbc
2022
from pytest_databases.docker.mssql import MSSQLService
2123
2224
pytest_plugins = ["pytest_databases.docker.mssql"]
2325
24-
def test(mssql_service: MSSQLService) -> None:
25-
conn = pymssql.connect(
26-
host=mssql_service.host,
27-
port=str(mssql_service.port),
28-
database=mssql_service.database,
29-
user=mssql_service.user,
30-
password=mssql_service.password,
31-
timeout=2,
32-
)
33-
with conn.cursor() as cursor:
34-
cursor.execute("select 1 as is_available")
35-
resp = cursor.fetchone()
36-
assert resp is not None and resp[0] == 1
37-
38-
def test(mssql_connection: pymssql.Connection) -> None:
39-
with mssql_connection.cursor() as cursor:
40-
cursor.execute("CREATE view simple_table as SELECT 1 as the_value")
41-
cursor.execute("select * from simple_table")
42-
result = cursor.fetchall()
43-
assert result is not None and result[0][0] == 1
44-
cursor.execute("drop view simple_table")
26+
def test_sql_server_service(mssql_service: MSSQLService) -> None:
27+
with pyodbc.connect(mssql_service.connection_string) as conn:
28+
cursor = conn.cursor()
29+
cursor.execute("SELECT 1 AS is_available")
30+
row = cursor.fetchone()
31+
assert row is not None and row[0] == 1
4532
4633
Available Fixtures
4734
------------------
4835

4936
* ``mssql_image``: The Docker image to use for SQL Server.
37+
* ``mssql_user``: The SQL Server user exposed on ``mssql_service``.
38+
* ``mssql_password``: The SQL Server password exposed on ``mssql_service``.
39+
* ``mssql_database``: The database created for ``mssql_service``.
5040
* ``mssql_service``: A fixture that provides a SQL Server service.
51-
* ``mssql_connection``: A fixture that provides a SQL Server connection.
5241

5342
Service API
5443
-----------

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ gizmosql = ["adbc-driver-flightsql", "pyarrow"]
6969
keydb = ["redis"]
7070
mariadb = []
7171
mongodb = ["pymongo"]
72-
mssql = ["pymssql"]
72+
mssql = []
7373
mysql = []
7474
oracle = ["oracledb"]
7575
postgres = ["psycopg>=3"]

src/pytest_databases/docker/dolt.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,38 @@ def platform() -> str:
3434
return "linux/x86_64"
3535

3636

37+
@pytest.fixture(scope="session")
38+
def dolt_user() -> str:
39+
return os.getenv("DOLT_USER", "app")
40+
41+
42+
@pytest.fixture(scope="session")
43+
def dolt_password() -> str:
44+
return os.getenv("DOLT_PASSWORD", "super-secret")
45+
46+
47+
@pytest.fixture(scope="session")
48+
def dolt_root_password() -> str:
49+
return os.getenv("DOLT_ROOT_PASSWORD", "super-secret")
50+
51+
52+
@pytest.fixture(scope="session")
53+
def dolt_database() -> str:
54+
return os.getenv("DOLT_DATABASE", "db")
55+
56+
3757
@contextlib.contextmanager
3858
def _provide_dolt_service(
3959
docker_service: DockerService,
4060
image: str,
4161
name: str,
4262
isolation_level: XdistIsolationLevel,
4363
platform: str,
64+
user: str,
65+
password: str,
66+
root_password: str,
67+
database: str,
4468
) -> Generator[DoltService, None, None]:
45-
user = os.getenv("DOLT_USER", "app")
46-
password = os.getenv("DOLT_PASSWORD", "super-secret")
47-
root_password = os.getenv("DOLT_ROOT_PASSWORD", "super-secret")
48-
database = os.getenv("DOLT_DATABASE", "db")
49-
5069
def check(_service: ServiceContainer) -> bool:
5170
container_name = f"pytest_databases_{name}"
5271
container = docker_service._get_container(container_name)
@@ -121,12 +140,20 @@ def dolt_service(
121140
docker_service: DockerService,
122141
xdist_dolt_isolation_level: XdistIsolationLevel,
123142
platform: str,
143+
dolt_user: str,
144+
dolt_password: str,
145+
dolt_root_password: str,
146+
dolt_database: str,
124147
) -> Generator[DoltService, None, None]:
125148
with _provide_dolt_service(
126149
image="dolthub/dolt-sql-server:latest",
127150
name="dolt",
128151
docker_service=docker_service,
129152
isolation_level=xdist_dolt_isolation_level,
130153
platform=platform,
154+
user=dolt_user,
155+
password=dolt_password,
156+
root_password=dolt_root_password,
157+
database=dolt_database,
131158
) as service:
132159
yield service

0 commit comments

Comments
 (0)