pytest-servex 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_servex-0.1.1/.gitignore +42 -0
- pytest_servex-0.1.1/CHANGELOG.md +22 -0
- pytest_servex-0.1.1/LICENSE +21 -0
- pytest_servex-0.1.1/PKG-INFO +149 -0
- pytest_servex-0.1.1/README.md +119 -0
- pytest_servex-0.1.1/pyproject.toml +124 -0
- pytest_servex-0.1.1/src/pytest_servex/__init__.py +53 -0
- pytest_servex-0.1.1/src/pytest_servex/_engine.py +183 -0
- pytest_servex-0.1.1/src/pytest_servex/errors.py +65 -0
- pytest_servex-0.1.1/src/pytest_servex/lifecycle.py +325 -0
- pytest_servex-0.1.1/src/pytest_servex/plugin.py +112 -0
- pytest_servex-0.1.1/src/pytest_servex/postgres.py +171 -0
- pytest_servex-0.1.1/src/pytest_servex/py.typed +0 -0
- pytest_servex-0.1.1/src/pytest_servex/spec.py +170 -0
- pytest_servex-0.1.1/tests/__init__.py +0 -0
- pytest_servex-0.1.1/tests/docker_available.py +18 -0
- pytest_servex-0.1.1/tests/test_flows.py +146 -0
- pytest_servex-0.1.1/tests/test_lifecycle.py +85 -0
- pytest_servex-0.1.1/tests/test_plugin.py +126 -0
- pytest_servex-0.1.1/tests/test_units.py +157 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
|
|
7
|
+
# Build artifacts
|
|
8
|
+
/dist/
|
|
9
|
+
/build/
|
|
10
|
+
/site/
|
|
11
|
+
/public/
|
|
12
|
+
|
|
13
|
+
# uv / venv
|
|
14
|
+
.venv/
|
|
15
|
+
uv.lock.bak
|
|
16
|
+
|
|
17
|
+
# Tool caches
|
|
18
|
+
.pytest_cache/
|
|
19
|
+
.ruff_cache/
|
|
20
|
+
.pyright/
|
|
21
|
+
.mypy_cache/
|
|
22
|
+
.moon/cache/
|
|
23
|
+
|
|
24
|
+
# Editor
|
|
25
|
+
.vscode/
|
|
26
|
+
.idea/
|
|
27
|
+
*.swp
|
|
28
|
+
|
|
29
|
+
# Local session logs
|
|
30
|
+
logs/
|
|
31
|
+
|
|
32
|
+
# Personal, machine-specific agent overrides (AGENTS.md is tracked)
|
|
33
|
+
AGENTS.local.md
|
|
34
|
+
CLAUDE.local.md
|
|
35
|
+
|
|
36
|
+
# Claude Code: per-machine local settings + worktrees are local; .claude/settings.json IS tracked.
|
|
37
|
+
.claude/settings.local.json
|
|
38
|
+
.claude/worktrees/
|
|
39
|
+
|
|
40
|
+
# Local agent wiring: names cabildo-issues-mcp, which is not a dependency of this
|
|
41
|
+
# package. docs/issues/ IS tracked — the register is plain markdown anyone can read.
|
|
42
|
+
.mcp.json
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `servex_postgres`: a Postgres database for each worker, copied from a template built once per run.
|
|
13
|
+
- `servex_postgres_prepare`: override it to run migrations or insert seed data into the template.
|
|
14
|
+
- `SERVEX_POSTGRES_URL` uses an existing server instead of starting a container.
|
|
15
|
+
- `SERVEX_POSTGRES_IMAGE` picks the Postgres image, including Postgres 18.
|
|
16
|
+
- Containers, networks and volumes left by a killed run are removed by the next run.
|
|
17
|
+
- `Network`, `Volume`, `Container` specs and `start`, `stop`, `running` to use containers outside pytest.
|
|
18
|
+
- `Container(pull=...)` with `missing`, `always`, `never`, plus `entrypoint`, `user`, `memory`, `shm_size` and `host_config`.
|
|
19
|
+
- Errors subclass built-ins: `NotReady` is a `TimeoutError`, `NotFound` a `LookupError`, `DockerUnavailable` a `ConnectionError`.
|
|
20
|
+
- A container that exits while starting fails at once with its logs, instead of waiting for the timeout.
|
|
21
|
+
- `SERVEX_HOST` sets where tests connect when the published ports are not on the `DOCKER_HOST` address.
|
|
22
|
+
- No docker SDK: the Docker API is called with the standard library.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jorge Cardona
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytest-servex
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Pytest fixtures that start test services in Docker once per run and give each worker its own database.
|
|
5
|
+
Project-URL: Homepage, https://gitlab.com/cardona-oss/pytest-servex
|
|
6
|
+
Project-URL: Repository, https://gitlab.com/cardona-oss/pytest-servex
|
|
7
|
+
Project-URL: Documentation, https://cardona-oss.gitlab.io/pytest-servex/
|
|
8
|
+
Project-URL: Changelog, https://gitlab.com/cardona-oss/pytest-servex/-/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://gitlab.com/cardona-oss/pytest-servex/-/issues
|
|
10
|
+
Author-email: Jorge Cardona <jorgeecardona@gmail.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: docker,fixtures,parallel,postgres,pytest,testing
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Framework :: Pytest
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Testing
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Requires-Dist: psycopg>=3.2
|
|
24
|
+
Requires-Dist: pytest>=8
|
|
25
|
+
Provides-Extra: docs
|
|
26
|
+
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
|
|
27
|
+
Requires-Dist: mkdocs>=1.6; extra == 'docs'
|
|
28
|
+
Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# pytest-servex
|
|
32
|
+
|
|
33
|
+
[](https://gitlab.com/cardona-oss/pytest-servex/-/pipelines)
|
|
34
|
+
[](https://pypi.org/project/pytest-servex/)
|
|
35
|
+
[](https://pypi.org/project/pytest-servex/)
|
|
36
|
+
[](https://gitlab.com/cardona-oss/pytest-servex/-/blob/main/LICENSE)
|
|
37
|
+
|
|
38
|
+
Pytest fixtures that start test services in Docker once per run and give each worker its own
|
|
39
|
+
database. Version 0.1 supports Postgres.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install pytest-servex "psycopg[binary]"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires Python 3.12+ and a Docker daemon. Talks to the Docker API directly with the standard
|
|
48
|
+
library: no docker SDK, no requests.
|
|
49
|
+
|
|
50
|
+
## Quickstart
|
|
51
|
+
|
|
52
|
+
Request `servex_postgres` in a test. It is a database of your own, on a container started once
|
|
53
|
+
for the run:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import psycopg
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_insert(servex_postgres):
|
|
60
|
+
with psycopg.connect(servex_postgres.url) as conn:
|
|
61
|
+
conn.execute("CREATE TABLE t (x int)")
|
|
62
|
+
conn.execute("INSERT INTO t VALUES (1)")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To run migrations once, override `servex_postgres_prepare` in `conftest.py`. Every worker
|
|
66
|
+
database starts as a copy of the result:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import subprocess
|
|
70
|
+
|
|
71
|
+
import pytest
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.fixture(scope="session")
|
|
75
|
+
def servex_postgres_prepare():
|
|
76
|
+
def prepare(url: str) -> None:
|
|
77
|
+
subprocess.run(["alembic", "upgrade", "head"], env={"DATABASE_URL": url}, check=True)
|
|
78
|
+
|
|
79
|
+
return prepare
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## How it works
|
|
83
|
+
|
|
84
|
+
1. `servex_postgres_server` starts one Postgres container for the run, with `fsync` off and
|
|
85
|
+
data on tmpfs.
|
|
86
|
+
2. `servex_postgres_template` creates the database `servex_template` and runs your prepare
|
|
87
|
+
function on it, once.
|
|
88
|
+
3. `servex_postgres` copies the template into one database per worker
|
|
89
|
+
(`CREATE DATABASE servex_f0 TEMPLATE servex_template`). This copies files, so it takes
|
|
90
|
+
milliseconds instead of a migration run.
|
|
91
|
+
|
|
92
|
+
Under [pytest-parallex](https://pypi.org/project/pytest-parallex/) steps 1 and 2 run once in
|
|
93
|
+
the controller, before the fork. Under pytest-xdist each worker runs its own session, so each
|
|
94
|
+
worker starts its own container.
|
|
95
|
+
|
|
96
|
+
## Outside pytest
|
|
97
|
+
|
|
98
|
+
Specs are frozen dataclasses. `running` starts one on enter and removes it on exit, so nested
|
|
99
|
+
blocks stop in reverse order:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from dataclasses import replace
|
|
103
|
+
|
|
104
|
+
from pytest_servex import POSTGRES, Network, running
|
|
105
|
+
|
|
106
|
+
net = Network("app")
|
|
107
|
+
pg = replace(POSTGRES, networks=(net,), alias="db", pull="never")
|
|
108
|
+
|
|
109
|
+
with running(net), running(pg) as started:
|
|
110
|
+
print(started.endpoint(5432)) # Endpoint(host='127.0.0.1', port=32771)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Errors subclass the built-in they resemble, and all subclass `ServexError`:
|
|
114
|
+
|
|
115
|
+
| Error | Also a | When |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| `NotReady` | `TimeoutError` | The ready check timed out, or the container exited first. Has `.logs`. |
|
|
118
|
+
| `ImageNotFound` | `LookupError` | The image is missing and `pull="never"`, or the pull failed. |
|
|
119
|
+
| `NotFound` | `LookupError` | Docker has no such object (HTTP 404). |
|
|
120
|
+
| `Conflict` | | A name is taken, or a network or volume is still in use (HTTP 409). |
|
|
121
|
+
| `DockerUnavailable` | `ConnectionError` | The Docker socket is missing or refuses connections. |
|
|
122
|
+
|
|
123
|
+
## Configuration
|
|
124
|
+
|
|
125
|
+
- `SERVEX_POSTGRES_URL`: use this server and start nothing (for example a CI service). It must
|
|
126
|
+
point at a database whose user may create databases.
|
|
127
|
+
- `SERVEX_POSTGRES_IMAGE`: the image to start. Default `postgres:17-alpine`.
|
|
128
|
+
- `DOCKER_HOST`: the Docker API, `unix://` or `tcp://`. Podman's Docker-compatible socket is
|
|
129
|
+
meant to work but is not tested yet.
|
|
130
|
+
- `SERVEX_HOST`: where tests connect to published ports, when that is not the `DOCKER_HOST`
|
|
131
|
+
address (for example `docker` with a GitLab `docker:dind` service).
|
|
132
|
+
|
|
133
|
+
## Compared to testcontainers
|
|
134
|
+
|
|
135
|
+
- No Ryuk container. Containers carry labels with the run's pid. The next run removes the
|
|
136
|
+
containers of runs that were killed.
|
|
137
|
+
- No Docker client crosses a fork. Fixtures hand workers plain URL strings.
|
|
138
|
+
- A template database and one copy per worker are built in, not left to each `conftest.py`.
|
|
139
|
+
|
|
140
|
+
## Links
|
|
141
|
+
|
|
142
|
+
- Documentation: https://cardona-oss.gitlab.io/pytest-servex/
|
|
143
|
+
- Source: https://gitlab.com/cardona-oss/pytest-servex
|
|
144
|
+
- Issues: https://gitlab.com/cardona-oss/pytest-servex/-/issues
|
|
145
|
+
- Changelog: https://gitlab.com/cardona-oss/pytest-servex/-/blob/main/CHANGELOG.md
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT © 2026 Jorge Cardona.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# pytest-servex
|
|
2
|
+
|
|
3
|
+
[](https://gitlab.com/cardona-oss/pytest-servex/-/pipelines)
|
|
4
|
+
[](https://pypi.org/project/pytest-servex/)
|
|
5
|
+
[](https://pypi.org/project/pytest-servex/)
|
|
6
|
+
[](https://gitlab.com/cardona-oss/pytest-servex/-/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Pytest fixtures that start test services in Docker once per run and give each worker its own
|
|
9
|
+
database. Version 0.1 supports Postgres.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install pytest-servex "psycopg[binary]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires Python 3.12+ and a Docker daemon. Talks to the Docker API directly with the standard
|
|
18
|
+
library: no docker SDK, no requests.
|
|
19
|
+
|
|
20
|
+
## Quickstart
|
|
21
|
+
|
|
22
|
+
Request `servex_postgres` in a test. It is a database of your own, on a container started once
|
|
23
|
+
for the run:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import psycopg
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_insert(servex_postgres):
|
|
30
|
+
with psycopg.connect(servex_postgres.url) as conn:
|
|
31
|
+
conn.execute("CREATE TABLE t (x int)")
|
|
32
|
+
conn.execute("INSERT INTO t VALUES (1)")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
To run migrations once, override `servex_postgres_prepare` in `conftest.py`. Every worker
|
|
36
|
+
database starts as a copy of the result:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import subprocess
|
|
40
|
+
|
|
41
|
+
import pytest
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.fixture(scope="session")
|
|
45
|
+
def servex_postgres_prepare():
|
|
46
|
+
def prepare(url: str) -> None:
|
|
47
|
+
subprocess.run(["alembic", "upgrade", "head"], env={"DATABASE_URL": url}, check=True)
|
|
48
|
+
|
|
49
|
+
return prepare
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## How it works
|
|
53
|
+
|
|
54
|
+
1. `servex_postgres_server` starts one Postgres container for the run, with `fsync` off and
|
|
55
|
+
data on tmpfs.
|
|
56
|
+
2. `servex_postgres_template` creates the database `servex_template` and runs your prepare
|
|
57
|
+
function on it, once.
|
|
58
|
+
3. `servex_postgres` copies the template into one database per worker
|
|
59
|
+
(`CREATE DATABASE servex_f0 TEMPLATE servex_template`). This copies files, so it takes
|
|
60
|
+
milliseconds instead of a migration run.
|
|
61
|
+
|
|
62
|
+
Under [pytest-parallex](https://pypi.org/project/pytest-parallex/) steps 1 and 2 run once in
|
|
63
|
+
the controller, before the fork. Under pytest-xdist each worker runs its own session, so each
|
|
64
|
+
worker starts its own container.
|
|
65
|
+
|
|
66
|
+
## Outside pytest
|
|
67
|
+
|
|
68
|
+
Specs are frozen dataclasses. `running` starts one on enter and removes it on exit, so nested
|
|
69
|
+
blocks stop in reverse order:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from dataclasses import replace
|
|
73
|
+
|
|
74
|
+
from pytest_servex import POSTGRES, Network, running
|
|
75
|
+
|
|
76
|
+
net = Network("app")
|
|
77
|
+
pg = replace(POSTGRES, networks=(net,), alias="db", pull="never")
|
|
78
|
+
|
|
79
|
+
with running(net), running(pg) as started:
|
|
80
|
+
print(started.endpoint(5432)) # Endpoint(host='127.0.0.1', port=32771)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Errors subclass the built-in they resemble, and all subclass `ServexError`:
|
|
84
|
+
|
|
85
|
+
| Error | Also a | When |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| `NotReady` | `TimeoutError` | The ready check timed out, or the container exited first. Has `.logs`. |
|
|
88
|
+
| `ImageNotFound` | `LookupError` | The image is missing and `pull="never"`, or the pull failed. |
|
|
89
|
+
| `NotFound` | `LookupError` | Docker has no such object (HTTP 404). |
|
|
90
|
+
| `Conflict` | | A name is taken, or a network or volume is still in use (HTTP 409). |
|
|
91
|
+
| `DockerUnavailable` | `ConnectionError` | The Docker socket is missing or refuses connections. |
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
- `SERVEX_POSTGRES_URL`: use this server and start nothing (for example a CI service). It must
|
|
96
|
+
point at a database whose user may create databases.
|
|
97
|
+
- `SERVEX_POSTGRES_IMAGE`: the image to start. Default `postgres:17-alpine`.
|
|
98
|
+
- `DOCKER_HOST`: the Docker API, `unix://` or `tcp://`. Podman's Docker-compatible socket is
|
|
99
|
+
meant to work but is not tested yet.
|
|
100
|
+
- `SERVEX_HOST`: where tests connect to published ports, when that is not the `DOCKER_HOST`
|
|
101
|
+
address (for example `docker` with a GitLab `docker:dind` service).
|
|
102
|
+
|
|
103
|
+
## Compared to testcontainers
|
|
104
|
+
|
|
105
|
+
- No Ryuk container. Containers carry labels with the run's pid. The next run removes the
|
|
106
|
+
containers of runs that were killed.
|
|
107
|
+
- No Docker client crosses a fork. Fixtures hand workers plain URL strings.
|
|
108
|
+
- A template database and one copy per worker are built in, not left to each `conftest.py`.
|
|
109
|
+
|
|
110
|
+
## Links
|
|
111
|
+
|
|
112
|
+
- Documentation: https://cardona-oss.gitlab.io/pytest-servex/
|
|
113
|
+
- Source: https://gitlab.com/cardona-oss/pytest-servex
|
|
114
|
+
- Issues: https://gitlab.com/cardona-oss/pytest-servex/-/issues
|
|
115
|
+
- Changelog: https://gitlab.com/cardona-oss/pytest-servex/-/blob/main/CHANGELOG.md
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT © 2026 Jorge Cardona.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pytest-servex"
|
|
3
|
+
dynamic = ["version"] # the single source of truth is __version__ in src/pytest_servex/__init__.py (see [tool.hatch.version])
|
|
4
|
+
description = "Pytest fixtures that start test services in Docker once per run and give each worker its own database."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Jorge Cardona", email = "jorgeecardona@gmail.com" }]
|
|
10
|
+
keywords = ["pytest", "docker", "postgres", "testing", "fixtures", "parallel"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
"Framework :: Pytest",
|
|
18
|
+
"Topic :: Software Development :: Testing",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"pytest>=8",
|
|
23
|
+
# psycopg needs a libpq: install psycopg[binary] or psycopg[c] alongside, or have libpq.
|
|
24
|
+
"psycopg>=3.2",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
# docs are an *extra* (not a uv dependency-group) so Read the Docs can install them via pip
|
|
29
|
+
docs = [
|
|
30
|
+
"mkdocs>=1.6",
|
|
31
|
+
"mkdocs-material>=9.5",
|
|
32
|
+
"mkdocstrings[python]>=0.27",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://gitlab.com/cardona-oss/pytest-servex"
|
|
37
|
+
Repository = "https://gitlab.com/cardona-oss/pytest-servex"
|
|
38
|
+
Documentation = "https://cardona-oss.gitlab.io/pytest-servex/"
|
|
39
|
+
Changelog = "https://gitlab.com/cardona-oss/pytest-servex/-/blob/main/CHANGELOG.md"
|
|
40
|
+
Issues = "https://gitlab.com/cardona-oss/pytest-servex/-/issues"
|
|
41
|
+
|
|
42
|
+
[project.entry-points.pytest11]
|
|
43
|
+
servex = "pytest_servex.plugin"
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["hatchling"]
|
|
47
|
+
build-backend = "hatchling.build"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.version]
|
|
50
|
+
# The version lives as __version__ in the package itself; hatchling reads it (by regex, no import) so
|
|
51
|
+
# pyproject and the runtime never disagree. scripts/bump-version rewrites that literal.
|
|
52
|
+
path = "src/pytest_servex/__init__.py"
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.wheel]
|
|
55
|
+
packages = ["src/pytest_servex"]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.sdist]
|
|
58
|
+
include = ["src", "tests", "README.md", "CHANGELOG.md", "LICENSE"]
|
|
59
|
+
|
|
60
|
+
[tool.uv]
|
|
61
|
+
# The version is dynamic (hatchling reads __version__ from the file below), so uv must watch it too:
|
|
62
|
+
# declaring cache-keys REPLACES uv's defaults, so pyproject.toml is listed explicitly alongside it.
|
|
63
|
+
# Without __init__.py here, bumping the version would not trigger an editable reinstall.
|
|
64
|
+
cache-keys = [{ file = "pyproject.toml" }, { file = "src/pytest_servex/__init__.py" }]
|
|
65
|
+
|
|
66
|
+
[dependency-groups]
|
|
67
|
+
dev = [
|
|
68
|
+
"ruff>=0.6",
|
|
69
|
+
"pyright[nodejs]>=1.1.390",
|
|
70
|
+
"pytest>=8",
|
|
71
|
+
"psycopg[binary]>=3.2",
|
|
72
|
+
"pytest-parallex>=0.2.6",
|
|
73
|
+
"musil>=0.36",
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
[tool.pytest.ini_options]
|
|
77
|
+
testpaths = ["tests"]
|
|
78
|
+
addopts = "-q -p pytester"
|
|
79
|
+
|
|
80
|
+
[tool.ruff]
|
|
81
|
+
line-length = 100
|
|
82
|
+
target-version = "py312"
|
|
83
|
+
src = ["src", "tests"]
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint]
|
|
86
|
+
select = ["ALL"]
|
|
87
|
+
# The canonical base ignore list shared across the oss/ libraries. E501 (line length) is handled by
|
|
88
|
+
# the formatter; COM812/ISC001 conflict with the formatter; D1/D401 relax docstring presence/mood;
|
|
89
|
+
# TRY003/EM101/EM102 allow inline exception messages; CPY001 drops the copyright-header demand;
|
|
90
|
+
# PLC0415 allows non-top-level imports; TC001/TC002/TC003 don't force type-only import blocks.
|
|
91
|
+
ignore = [
|
|
92
|
+
"E501",
|
|
93
|
+
"COM812",
|
|
94
|
+
"ISC001",
|
|
95
|
+
"D1",
|
|
96
|
+
"D401",
|
|
97
|
+
"TRY003",
|
|
98
|
+
"EM101",
|
|
99
|
+
"EM102",
|
|
100
|
+
"CPY001",
|
|
101
|
+
"PLC0415",
|
|
102
|
+
"TC001",
|
|
103
|
+
"TC002",
|
|
104
|
+
"TC003",
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
[tool.ruff.lint.pydocstyle]
|
|
108
|
+
convention = "pep257"
|
|
109
|
+
|
|
110
|
+
[tool.ruff.lint.per-file-ignores]
|
|
111
|
+
# Tests may assert (S101), use magic values (PLR2004), take unused fixtures (ARG), pass Any to typed
|
|
112
|
+
# calls (ANN401), and group assertions pytest would otherwise split (PT018).
|
|
113
|
+
"tests/**/*.py" = ["S101", "PLR2004", "ARG", "ANN401", "PT018"]
|
|
114
|
+
|
|
115
|
+
[tool.ruff.lint.isort]
|
|
116
|
+
known-first-party = ["pytest_servex"]
|
|
117
|
+
|
|
118
|
+
[tool.pyright]
|
|
119
|
+
include = ["src", "tests"]
|
|
120
|
+
extraPaths = ["src"]
|
|
121
|
+
pythonVersion = "3.12"
|
|
122
|
+
typeCheckingMode = "strict"
|
|
123
|
+
venvPath = "."
|
|
124
|
+
venv = ".venv"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Pytest fixtures that start test services in Docker once per run and give each worker its own database."""
|
|
2
|
+
|
|
3
|
+
from pytest_servex.errors import (
|
|
4
|
+
Conflict,
|
|
5
|
+
DockerError,
|
|
6
|
+
DockerUnavailable,
|
|
7
|
+
ImageNotFound,
|
|
8
|
+
NotFound,
|
|
9
|
+
NotReady,
|
|
10
|
+
ServexError,
|
|
11
|
+
)
|
|
12
|
+
from pytest_servex.lifecycle import remove_stale, running, start, stop
|
|
13
|
+
from pytest_servex.postgres import POSTGRES, PostgresDatabase, PostgresServer
|
|
14
|
+
from pytest_servex.spec import (
|
|
15
|
+
Container,
|
|
16
|
+
Endpoint,
|
|
17
|
+
Mount,
|
|
18
|
+
Network,
|
|
19
|
+
RunningContainer,
|
|
20
|
+
RunningNetwork,
|
|
21
|
+
RunningVolume,
|
|
22
|
+
Tmpfs,
|
|
23
|
+
Volume,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__version__ = "0.1.1" # the single source of truth; pyproject reads it via [tool.hatch.version]
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"POSTGRES",
|
|
30
|
+
"Conflict",
|
|
31
|
+
"Container",
|
|
32
|
+
"DockerError",
|
|
33
|
+
"DockerUnavailable",
|
|
34
|
+
"Endpoint",
|
|
35
|
+
"ImageNotFound",
|
|
36
|
+
"Mount",
|
|
37
|
+
"Network",
|
|
38
|
+
"NotFound",
|
|
39
|
+
"NotReady",
|
|
40
|
+
"PostgresDatabase",
|
|
41
|
+
"PostgresServer",
|
|
42
|
+
"RunningContainer",
|
|
43
|
+
"RunningNetwork",
|
|
44
|
+
"RunningVolume",
|
|
45
|
+
"ServexError",
|
|
46
|
+
"Tmpfs",
|
|
47
|
+
"Volume",
|
|
48
|
+
"__version__",
|
|
49
|
+
"remove_stale",
|
|
50
|
+
"running",
|
|
51
|
+
"start",
|
|
52
|
+
"stop",
|
|
53
|
+
]
|