Skip to content

Commit e812939

Browse files
committed
1.2.1 update readme, conftest in example
1 parent fb10177 commit e812939

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,28 @@ Default client fixture names the plugin will look for (in order):
189189

190190
If you use a different fixture name, you can provide one or more names via the CLI flag `--api-cov-client-fixture-names` (repeatable) or in `pyproject.toml` under `[tool.pytest_api_cov]` as `client_fixture_names` (a list).
191191

192-
#### Option 1: Helper Function
192+
193+
#### Option 1: Configuration-Based (recommended for most users)
194+
195+
Configure one or more existing fixture names to be discovered and wrapped automatically by the plugin.
196+
197+
Example `pyproject.toml`:
198+
199+
```toml
200+
[tool.pytest_api_cov]
201+
# Provide a list of candidate fixture names the plugin should try (order matters)
202+
client_fixture_names = ["my_custom_client"]
203+
```
204+
205+
Or use the CLI flag multiple times:
206+
207+
```bash
208+
pytest --api-cov-report --api-cov-client-fixture-names=my_custom_client --api-cov-client-fixture-names=another_fixture
209+
```
210+
211+
If the configured fixture(s) are not found, the plugin will try to use an `app` fixture (if present) to create a tracked client. If neither is available or the plugin cannot extract the app from a discovered client fixture, the tests will still run — coverage will simply be unavailable and a warning will be logged.
212+
213+
#### Option 2: Helper Function
193214

194215
Use the `create_coverage_fixture` helper to create a custom fixture name:
195216

@@ -221,25 +242,6 @@ def test_with_flask_client(flask_client):
221242

222243
The helper returns a pytest fixture you can assign to a name in `conftest.py`.
223244

224-
#### Option 2: Configuration-Based (recommended for most users)
225-
226-
Configure one or more existing fixture names to be discovered and wrapped automatically by the plugin.
227-
228-
Example `pyproject.toml`:
229-
230-
```toml
231-
[tool.pytest_api_cov]
232-
# Provide a list of candidate fixture names the plugin should try (order matters)
233-
client_fixture_names = ["my_custom_client"]
234-
```
235-
236-
Or use the CLI flag multiple times:
237-
238-
```bash
239-
pytest --api-cov-report --api-cov-client-fixture-names=my_custom_client --api-cov-client-fixture-names=another_fixture
240-
```
241-
242-
If the configured fixture(s) are not found, the plugin will try to use an `app` fixture (if present) to create a tracked client. If neither is available or the plugin cannot extract the app from a discovered client fixture, the tests will still run — coverage will simply be unavailable and a warning will be logged.
243245

244246
### Configuration Options
245247

example/conftest.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

example/tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""example/conftest.py"""
2+
3+
import pytest
4+
from fastapi.testclient import TestClient
5+
6+
from example.src.main import app as fastapi_app
7+
from pytest_api_cov.plugin import create_coverage_fixture
8+
9+
10+
@pytest.fixture
11+
def original_client():
12+
"""Original FastAPI test client fixture.
13+
14+
This fixture demonstrates an existing user-provided client that we can wrap
15+
with `create_coverage_fixture` so tests can continue to use the familiar
16+
`client` fixture name while gaining API coverage tracking.
17+
"""
18+
return TestClient(fastapi_app)
19+
20+
21+
# Create a wrapped fixture named 'client' that wraps the existing 'original_client'.
22+
# Tests can continue to request the `client` fixture as before and coverage will be
23+
# collected when pytest is run with --api-cov-report.
24+
client = create_coverage_fixture("client", "original_client")

0 commit comments

Comments
 (0)