pytest-api-core 1.0.2__tar.gz → 1.0.3__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.
Files changed (39) hide show
  1. pytest_api_core-1.0.3/MANIFEST.in +2 -0
  2. pytest_api_core-1.0.3/PKG-INFO +218 -0
  3. pytest_api_core-1.0.3/README.md +155 -0
  4. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/pyproject.toml +6 -6
  5. pytest_api_core-1.0.3/src/pytest_api_core/__init__.py +41 -0
  6. pytest_api_core-1.0.3/src/pytest_api_core/assertions/__init__.py +24 -0
  7. pytest_api_core-1.0.3/src/pytest_api_core/assertions/assert_utils.py +114 -0
  8. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/assertions/response_assertions.py +72 -35
  9. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/client/api_client.py +34 -11
  10. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/client/api_response.py +10 -2
  11. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/config/base_settings.py +16 -1
  12. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/config/config_manager.py +20 -9
  13. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/fixtures/api_fixtures.py +62 -15
  14. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/plugin.py +56 -15
  15. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/reporters/html_reporter.py +108 -56
  16. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/reporters/templates/report.html +78 -7
  17. pytest_api_core-1.0.3/src/pytest_api_core.egg-info/PKG-INFO +218 -0
  18. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core.egg-info/SOURCES.txt +2 -3
  19. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core.egg-info/requires.txt +5 -5
  20. pytest_api_core-1.0.2/MANIFEST.in +0 -4
  21. pytest_api_core-1.0.2/PKG-INFO +0 -317
  22. pytest_api_core-1.0.2/README.md +0 -254
  23. pytest_api_core-1.0.2/src/pytest_api_core/__init__.py +0 -20
  24. pytest_api_core-1.0.2/src/pytest_api_core/assertions/__init__.py +0 -3
  25. pytest_api_core-1.0.2/src/pytest_api_core.egg-info/PKG-INFO +0 -317
  26. pytest_api_core-1.0.2/tests/test_sample_api.py +0 -150
  27. pytest_api_core-1.0.2/tests/test_unit.py +0 -187
  28. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/LICENSE +0 -0
  29. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/setup.cfg +0 -0
  30. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/auth/__init__.py +0 -0
  31. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/auth/auth_handlers.py +0 -0
  32. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/client/__init__.py +0 -0
  33. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/config/__init__.py +0 -0
  34. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/config/env_loader.py +0 -0
  35. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/fixtures/__init__.py +0 -0
  36. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core/reporters/__init__.py +0 -0
  37. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core.egg-info/dependency_links.txt +0 -0
  38. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core.egg-info/entry_points.txt +0 -0
  39. {pytest_api_core-1.0.2 → pytest_api_core-1.0.3}/src/pytest_api_core.egg-info/top_level.txt +0 -0
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ include LICENSE
@@ -0,0 +1,218 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-api-core
3
+ Version: 1.0.3
4
+ Summary: Pytest API automation framework with custom HTML reporting, reusable fixtures, and fluent assertions
5
+ Author: QA Platform Team
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Subodh Singh
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/sksingh329/pytest-api-core-framework
29
+ Project-URL: Repository, https://github.com/sksingh329/pytest-api-core-framework
30
+ Project-URL: Documentation, https://github.com/sksingh329/pytest-api-core-framework/blob/develop/README.md
31
+ Project-URL: Bug Tracker, https://github.com/sksingh329/pytest-api-core-framework/issues
32
+ Project-URL: Changelog, https://github.com/sksingh329/pytest-api-core-framework/blob/develop/CHANGELOG.md
33
+ Keywords: pytest,api,testing,automation,html-report
34
+ Classifier: Development Status :: 5 - Production/Stable
35
+ Classifier: Framework :: Pytest
36
+ Classifier: Intended Audience :: Developers
37
+ Classifier: Topic :: Software Development :: Testing
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.9
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Operating System :: OS Independent
44
+ Requires-Python: >=3.9
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: pytest<10.0,>=7.4
48
+ Requires-Dist: requests<3.0,>=2.31
49
+ Requires-Dist: Jinja2<4.0,>=3.1
50
+ Requires-Dist: urllib3<3.0,>=2.0
51
+ Requires-Dist: jsonschema<5.0,>=4.20
52
+ Provides-Extra: dotenv
53
+ Requires-Dist: python-dotenv>=1.0; extra == "dotenv"
54
+ Provides-Extra: dev
55
+ Requires-Dist: pytest-mock>=3.12; extra == "dev"
56
+ Requires-Dist: responses>=0.25; extra == "dev"
57
+ Requires-Dist: black>=24.0; extra == "dev"
58
+ Requires-Dist: isort>=5.13; extra == "dev"
59
+ Requires-Dist: mypy>=1.8; extra == "dev"
60
+ Requires-Dist: twine>=5.0; extra == "dev"
61
+ Requires-Dist: build>=1.0; extra == "dev"
62
+ Dynamic: license-file
63
+
64
+ # pytest-api-core
65
+
66
+ [![PyPI version](https://img.shields.io/pypi/v/pytest-api-core)](https://pypi.org/project/pytest-api-core/)
67
+ [![Python](https://img.shields.io/pypi/pyversions/pytest-api-core)](https://pypi.org/project/pytest-api-core/)
68
+ [![License](https://img.shields.io/pypi/l/pytest-api-core)](LICENSE)
69
+
70
+ > A reusable pytest plugin for API automation — fluent assertions, built-in auth strategies, environment-aware configuration, and a self-contained HTML report.
71
+
72
+ ## Features
73
+
74
+ - **`APIClient`** — `requests.Session` wrapper with retry, timeout, and structured logging
75
+ - **Fluent assertions** — `assert_that(response).status_is(200).json_path("$.id").equals(1)`
76
+ (`json_path()` supports a small dot/bracket-index subset, not full JSONPath — see [docs/QUICKSTART.md](docs/QUICKSTART.md#json_path-syntax);
77
+ `response_time_under()` measures the whole request including any retries, not just the final attempt)
78
+ - **Auth strategies** — Bearer token, Basic, API Key (header/query), OAuth2 client credentials
79
+ (need something else, like an OAuth2 refresh-token flow or signed requests? subclass `AuthBase` — see [docs/QUICKSTART.md](docs/QUICKSTART.md#custom-auth-handlers))
80
+ - **Standalone assertion helpers** — `assert_equal`, `assert_contains`, `assert_matches`, `assert_matches_schema`, etc. for values outside an `APIResponse` — see [docs/QUICKSTART.md](docs/QUICKSTART.md#standalone-assertion-helpers)
81
+ - **Configurable retry policy** — max attempts, backoff factor, and retryable methods, overridable per environment (see below)
82
+ - **Environment config** — Python `settings.py` classes + `.env` file + env var overrides
83
+ - **Custom HTML report** — self-contained file with charts, filterable table, and request/response details
84
+ - **Auto-registered fixtures** — zero boilerplate in consuming projects
85
+
86
+ ---
87
+
88
+ ## Installation
89
+
90
+ ```bash
91
+ pip install pytest-api-core==1.0.3
92
+ ```
93
+
94
+ With `.env` file support (recommended):
95
+
96
+ ```bash
97
+ pip install "pytest-api-core[dotenv]==1.0.3"
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Quick start
103
+
104
+ ```python
105
+ # tests/test_posts.py
106
+ from pytest_api_core.assertions import assert_that
107
+
108
+ def test_get_post(api_client):
109
+ response = api_client.get("/posts/1")
110
+ assert_that(response).status_is(200).json_path("$.id").equals(1)
111
+
112
+ def test_create_post(api_client):
113
+ payload = {"title": "foo", "body": "bar", "userId": 1}
114
+ response = api_client.post("/posts", json=payload)
115
+ assert_that(response).status_is(201).has_key("id")
116
+ ```
117
+
118
+ ```bash
119
+ pytest tests/ --api-env=staging
120
+ ```
121
+
122
+ For full setup instructions — including `pytest.ini`, `config/settings.py`, `conftest.py` auth overrides, and CI integration — see **[docs/QUICKSTART.md](docs/QUICKSTART.md)**.
123
+
124
+ ---
125
+
126
+ ## Configuration
127
+
128
+ ### Resolution order (highest → lowest priority)
129
+
130
+ | Priority | Source |
131
+ |---|---|
132
+ | 1 | Shell / CI environment variables (`API_BASE_URL`, `API_TOKEN`, …) |
133
+ | 2 | `--api-base-url` CLI flag |
134
+ | 3 | `ENVIRONMENTS[env]` class in `settings_module` |
135
+ | 4 | Built-in defaults (`http://localhost`, timeout 30 s) |
136
+
137
+ ### Retry policy
138
+
139
+ `APIClient` retries idempotent requests (`GET`, `HEAD`, `OPTIONS`) on `500/502/503/504`
140
+ responses using `urllib3.Retry`. All three knobs follow the same env var → CLI flag →
141
+ `settings_module` → built-in default precedence as `base_url`:
142
+
143
+ | Setting | `settings_module` attribute | CLI flag | Env var | Default |
144
+ |---|---|---|---|---|
145
+ | Max retry attempts | `api_retry_total` | `--api-retry-total` | `API_RETRY_TOTAL` | `3` |
146
+ | Backoff factor | `api_retry_backoff_factor` | `--api-retry-backoff-factor` | `API_RETRY_BACKOFF_FACTOR` | `0.3` |
147
+ | Retryable methods | `api_retry_methods` | `--api-retry-methods` (comma-separated) | `API_RETRY_METHODS` (comma-separated) | `GET,HEAD,OPTIONS` |
148
+
149
+ Backoff factor `0.3` produces sleeps of `0s, 0.3s, 0.6s, 1.2s, ...` between attempts.
150
+
151
+ Example — a flakier staging environment gets more retries and a longer backoff:
152
+
153
+ ```python
154
+ # settings.py
155
+ class StagingSettings(BaseSettings):
156
+ base_url = "https://api.staging.mycompany.com"
157
+ api_retry_total = 5
158
+ api_retry_backoff_factor = 1.0
159
+ ```
160
+
161
+ Or per-run, without touching code:
162
+
163
+ ```bash
164
+ pytest tests/ --api-env=staging --api-retry-total=5 --api-retry-backoff-factor=1.0
165
+ ```
166
+
167
+ To disable retries entirely, pass `retry=None` directly when constructing an
168
+ `APIClient` yourself (not available as a config option, since "no retries" isn't
169
+ something you'd want to toggle per environment).
170
+
171
+ ### Key `pytest.ini` options
172
+
173
+ | Option | Description | Default |
174
+ |---|---|---|
175
+ | `api_env` | Active environment name | `dev` |
176
+ | `api_settings_module` | Dotted path to your settings module | — |
177
+ | `api_dotenv_file` | Path to `.env` file | `.env` |
178
+ | `api_log_level` | Framework log level | `WARNING` |
179
+ | `api_html_report` | HTML report path (supports `{env}`, `{timestamp}`) | — |
180
+ | `api_html_theme` | Report theme: `light` or `dark` | `dark` |
181
+ | `api_html_title` | Report browser tab title | `API Test Report` |
182
+ | `api_html_header` | Report page header text | `API Test Report` |
183
+
184
+ ### CLI flags
185
+
186
+ | Flag | Description |
187
+ |---|---|
188
+ | `--api-env` | Override active environment |
189
+ | `--api-base-url` | Override `base_url` |
190
+ | `--api-log-level` | Override framework log level |
191
+ | `--api-html-report` | Override HTML report path |
192
+ | `--api-retry-total` | Override max retry attempts (default: `3`) |
193
+ | `--api-retry-backoff-factor` | Override retry backoff factor (default: `0.3`) |
194
+ | `--api-retry-methods` | Override retryable HTTP methods, comma-separated (default: `GET,HEAD,OPTIONS`) |
195
+
196
+ ---
197
+
198
+ ## Fixtures
199
+
200
+ All fixtures are auto-registered — no imports needed in `conftest.py`.
201
+
202
+ | Fixture | Scope | Description |
203
+ |---|---|---|
204
+ | `api_config` | session | Resolved config dict for the active env |
205
+ | `auth_provider` | session | Auth strategy passed to `api_client` — override this alone to swap auth |
206
+ | `api_client` | session | Configured `APIClient` instance, depends on `auth_provider` |
207
+ | `api_bearer_auth` | function | `BearerAuth` from `API_TOKEN` env var |
208
+ | `api_basic_auth` | function | `BasicAuth` from `API_USERNAME` / `API_PASSWORD` |
209
+ | `api_key_auth` | function | `APIKeyAuth` from `API_KEY_NAME` / `API_KEY_VALUE` |
210
+
211
+ Override `auth_provider` in your project's `conftest.py` to inject custom auth without
212
+ redeclaring `api_client` — see [docs/QUICKSTART.md](docs/QUICKSTART.md#7-override-auth--testsconftestpy).
213
+
214
+ ---
215
+
216
+ ## License
217
+
218
+ See [LICENSE](LICENSE).
@@ -0,0 +1,155 @@
1
+ # pytest-api-core
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/pytest-api-core)](https://pypi.org/project/pytest-api-core/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/pytest-api-core)](https://pypi.org/project/pytest-api-core/)
5
+ [![License](https://img.shields.io/pypi/l/pytest-api-core)](LICENSE)
6
+
7
+ > A reusable pytest plugin for API automation — fluent assertions, built-in auth strategies, environment-aware configuration, and a self-contained HTML report.
8
+
9
+ ## Features
10
+
11
+ - **`APIClient`** — `requests.Session` wrapper with retry, timeout, and structured logging
12
+ - **Fluent assertions** — `assert_that(response).status_is(200).json_path("$.id").equals(1)`
13
+ (`json_path()` supports a small dot/bracket-index subset, not full JSONPath — see [docs/QUICKSTART.md](docs/QUICKSTART.md#json_path-syntax);
14
+ `response_time_under()` measures the whole request including any retries, not just the final attempt)
15
+ - **Auth strategies** — Bearer token, Basic, API Key (header/query), OAuth2 client credentials
16
+ (need something else, like an OAuth2 refresh-token flow or signed requests? subclass `AuthBase` — see [docs/QUICKSTART.md](docs/QUICKSTART.md#custom-auth-handlers))
17
+ - **Standalone assertion helpers** — `assert_equal`, `assert_contains`, `assert_matches`, `assert_matches_schema`, etc. for values outside an `APIResponse` — see [docs/QUICKSTART.md](docs/QUICKSTART.md#standalone-assertion-helpers)
18
+ - **Configurable retry policy** — max attempts, backoff factor, and retryable methods, overridable per environment (see below)
19
+ - **Environment config** — Python `settings.py` classes + `.env` file + env var overrides
20
+ - **Custom HTML report** — self-contained file with charts, filterable table, and request/response details
21
+ - **Auto-registered fixtures** — zero boilerplate in consuming projects
22
+
23
+ ---
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install pytest-api-core==1.0.3
29
+ ```
30
+
31
+ With `.env` file support (recommended):
32
+
33
+ ```bash
34
+ pip install "pytest-api-core[dotenv]==1.0.3"
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Quick start
40
+
41
+ ```python
42
+ # tests/test_posts.py
43
+ from pytest_api_core.assertions import assert_that
44
+
45
+ def test_get_post(api_client):
46
+ response = api_client.get("/posts/1")
47
+ assert_that(response).status_is(200).json_path("$.id").equals(1)
48
+
49
+ def test_create_post(api_client):
50
+ payload = {"title": "foo", "body": "bar", "userId": 1}
51
+ response = api_client.post("/posts", json=payload)
52
+ assert_that(response).status_is(201).has_key("id")
53
+ ```
54
+
55
+ ```bash
56
+ pytest tests/ --api-env=staging
57
+ ```
58
+
59
+ For full setup instructions — including `pytest.ini`, `config/settings.py`, `conftest.py` auth overrides, and CI integration — see **[docs/QUICKSTART.md](docs/QUICKSTART.md)**.
60
+
61
+ ---
62
+
63
+ ## Configuration
64
+
65
+ ### Resolution order (highest → lowest priority)
66
+
67
+ | Priority | Source |
68
+ |---|---|
69
+ | 1 | Shell / CI environment variables (`API_BASE_URL`, `API_TOKEN`, …) |
70
+ | 2 | `--api-base-url` CLI flag |
71
+ | 3 | `ENVIRONMENTS[env]` class in `settings_module` |
72
+ | 4 | Built-in defaults (`http://localhost`, timeout 30 s) |
73
+
74
+ ### Retry policy
75
+
76
+ `APIClient` retries idempotent requests (`GET`, `HEAD`, `OPTIONS`) on `500/502/503/504`
77
+ responses using `urllib3.Retry`. All three knobs follow the same env var → CLI flag →
78
+ `settings_module` → built-in default precedence as `base_url`:
79
+
80
+ | Setting | `settings_module` attribute | CLI flag | Env var | Default |
81
+ |---|---|---|---|---|
82
+ | Max retry attempts | `api_retry_total` | `--api-retry-total` | `API_RETRY_TOTAL` | `3` |
83
+ | Backoff factor | `api_retry_backoff_factor` | `--api-retry-backoff-factor` | `API_RETRY_BACKOFF_FACTOR` | `0.3` |
84
+ | Retryable methods | `api_retry_methods` | `--api-retry-methods` (comma-separated) | `API_RETRY_METHODS` (comma-separated) | `GET,HEAD,OPTIONS` |
85
+
86
+ Backoff factor `0.3` produces sleeps of `0s, 0.3s, 0.6s, 1.2s, ...` between attempts.
87
+
88
+ Example — a flakier staging environment gets more retries and a longer backoff:
89
+
90
+ ```python
91
+ # settings.py
92
+ class StagingSettings(BaseSettings):
93
+ base_url = "https://api.staging.mycompany.com"
94
+ api_retry_total = 5
95
+ api_retry_backoff_factor = 1.0
96
+ ```
97
+
98
+ Or per-run, without touching code:
99
+
100
+ ```bash
101
+ pytest tests/ --api-env=staging --api-retry-total=5 --api-retry-backoff-factor=1.0
102
+ ```
103
+
104
+ To disable retries entirely, pass `retry=None` directly when constructing an
105
+ `APIClient` yourself (not available as a config option, since "no retries" isn't
106
+ something you'd want to toggle per environment).
107
+
108
+ ### Key `pytest.ini` options
109
+
110
+ | Option | Description | Default |
111
+ |---|---|---|
112
+ | `api_env` | Active environment name | `dev` |
113
+ | `api_settings_module` | Dotted path to your settings module | — |
114
+ | `api_dotenv_file` | Path to `.env` file | `.env` |
115
+ | `api_log_level` | Framework log level | `WARNING` |
116
+ | `api_html_report` | HTML report path (supports `{env}`, `{timestamp}`) | — |
117
+ | `api_html_theme` | Report theme: `light` or `dark` | `dark` |
118
+ | `api_html_title` | Report browser tab title | `API Test Report` |
119
+ | `api_html_header` | Report page header text | `API Test Report` |
120
+
121
+ ### CLI flags
122
+
123
+ | Flag | Description |
124
+ |---|---|
125
+ | `--api-env` | Override active environment |
126
+ | `--api-base-url` | Override `base_url` |
127
+ | `--api-log-level` | Override framework log level |
128
+ | `--api-html-report` | Override HTML report path |
129
+ | `--api-retry-total` | Override max retry attempts (default: `3`) |
130
+ | `--api-retry-backoff-factor` | Override retry backoff factor (default: `0.3`) |
131
+ | `--api-retry-methods` | Override retryable HTTP methods, comma-separated (default: `GET,HEAD,OPTIONS`) |
132
+
133
+ ---
134
+
135
+ ## Fixtures
136
+
137
+ All fixtures are auto-registered — no imports needed in `conftest.py`.
138
+
139
+ | Fixture | Scope | Description |
140
+ |---|---|---|
141
+ | `api_config` | session | Resolved config dict for the active env |
142
+ | `auth_provider` | session | Auth strategy passed to `api_client` — override this alone to swap auth |
143
+ | `api_client` | session | Configured `APIClient` instance, depends on `auth_provider` |
144
+ | `api_bearer_auth` | function | `BearerAuth` from `API_TOKEN` env var |
145
+ | `api_basic_auth` | function | `BasicAuth` from `API_USERNAME` / `API_PASSWORD` |
146
+ | `api_key_auth` | function | `APIKeyAuth` from `API_KEY_NAME` / `API_KEY_VALUE` |
147
+
148
+ Override `auth_provider` in your project's `conftest.py` to inject custom auth without
149
+ redeclaring `api_client` — see [docs/QUICKSTART.md](docs/QUICKSTART.md#7-override-auth--testsconftestpy).
150
+
151
+ ---
152
+
153
+ ## License
154
+
155
+ See [LICENSE](LICENSE).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pytest-api-core"
7
- version = "1.0.2"
7
+ version = "1.0.3"
8
8
  description = "Pytest API automation framework with custom HTML reporting, reusable fixtures, and fluent assertions"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -24,11 +24,11 @@ classifiers = [
24
24
  ]
25
25
  requires-python = ">=3.9"
26
26
  dependencies = [
27
- "pytest>=7.4",
28
- "requests>=2.31",
29
- "Jinja2>=3.1",
30
- "urllib3>=2.0",
31
- "jsonschema>=4.20",
27
+ "pytest>=7.4,<10.0",
28
+ "requests>=2.31,<3.0",
29
+ "Jinja2>=3.1,<4.0",
30
+ "urllib3>=2.0,<3.0",
31
+ "jsonschema>=4.20,<5.0",
32
32
  ]
33
33
 
34
34
  [project.optional-dependencies]
@@ -0,0 +1,41 @@
1
+ """
2
+ pytest-api-core: Reusable API automation framework for pytest.
3
+ Auto-registered as a pytest plugin via entry_points["pytest11"].
4
+ """
5
+
6
+ from pytest_api_core.assertions.assert_utils import (
7
+ assert_contains,
8
+ assert_equal,
9
+ assert_equal_ignore_case,
10
+ assert_is_empty,
11
+ assert_is_not_empty,
12
+ assert_matches,
13
+ assert_not_equal,
14
+ )
15
+ from pytest_api_core.assertions.response_assertions import assert_that
16
+ from pytest_api_core.auth.auth_handlers import (
17
+ APIKeyAuth,
18
+ BasicAuth,
19
+ BearerAuth,
20
+ OAuth2ClientCredentials,
21
+ )
22
+ from pytest_api_core.client.api_client import APIClient
23
+ from pytest_api_core.client.api_response import APIResponse
24
+
25
+ __version__ = "1.0.0"
26
+ __all__ = [
27
+ "APIClient",
28
+ "APIResponse",
29
+ "assert_that",
30
+ "assert_equal",
31
+ "assert_not_equal",
32
+ "assert_equal_ignore_case",
33
+ "assert_contains",
34
+ "assert_matches",
35
+ "assert_is_empty",
36
+ "assert_is_not_empty",
37
+ "BearerAuth",
38
+ "BasicAuth",
39
+ "APIKeyAuth",
40
+ "OAuth2ClientCredentials",
41
+ ]
@@ -0,0 +1,24 @@
1
+ from pytest_api_core.assertions.assert_utils import (
2
+ assert_contains,
3
+ assert_equal,
4
+ assert_equal_ignore_case,
5
+ assert_is_empty,
6
+ assert_is_not_empty,
7
+ assert_matches,
8
+ assert_matches_schema,
9
+ assert_not_equal,
10
+ )
11
+ from pytest_api_core.assertions.response_assertions import ResponseAssertions, assert_that
12
+
13
+ __all__ = [
14
+ "ResponseAssertions",
15
+ "assert_that",
16
+ "assert_equal",
17
+ "assert_not_equal",
18
+ "assert_equal_ignore_case",
19
+ "assert_contains",
20
+ "assert_matches",
21
+ "assert_matches_schema",
22
+ "assert_is_empty",
23
+ "assert_is_not_empty",
24
+ ]
@@ -0,0 +1,114 @@
1
+ """
2
+ Generic, standalone string assertion utilities.
3
+
4
+ Usage
5
+ -----
6
+ from pytest_api_core.assertions import assert_equal
7
+
8
+ assert_equal(actual, expected)
9
+ assert_contains(actual, "substring")
10
+ assert_matches(actual, r"^\\d+$")
11
+ assert_matches_schema(actual, schema)
12
+
13
+ Unlike :class:`ResponseAssertions`, these are plain functions for comparing
14
+ arbitrary actual/expected strings — not tied to an ``APIResponse``.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import json
20
+ import logging
21
+ import re
22
+ from typing import Any
23
+
24
+ _assert_log = logging.getLogger("pytest_api_core.assertions")
25
+
26
+
27
+ def _emit(name: str, passed: bool, **detail: object) -> None:
28
+ """Emit a machine-readable sentinel line captured by HTMLReporter."""
29
+ _assert_log.debug(
30
+ "__API_ASSERT__ %s",
31
+ json.dumps({"name": name, "passed": passed, **detail}, separators=(",", ":")),
32
+ )
33
+
34
+
35
+ def _fail(message: str | None, default: str) -> None:
36
+ raise AssertionError(f"{message}\n {default}" if message else default)
37
+
38
+
39
+ def assert_equal(actual: str, expected: str, *, message: str | None = None) -> None:
40
+ """Assert *actual* equals *expected*."""
41
+ passed = actual == expected
42
+ _emit("assert_equal", passed, expected=expected, actual=actual)
43
+ if not passed:
44
+ _fail(message, f"Expected {expected!r}, got {actual!r}.")
45
+
46
+
47
+ def assert_not_equal(actual: str, expected: str, *, message: str | None = None) -> None:
48
+ """Assert *actual* does not equal *expected*."""
49
+ passed = actual != expected
50
+ _emit("assert_not_equal", passed, expected=expected, actual=actual)
51
+ if not passed:
52
+ _fail(message, f"Expected value to differ from {expected!r}, got {actual!r}.")
53
+
54
+
55
+ def assert_equal_ignore_case(actual: str, expected: str, *, message: str | None = None) -> None:
56
+ """Assert *actual* equals *expected*, ignoring case."""
57
+ passed = actual.lower() == expected.lower()
58
+ _emit("assert_equal_ignore_case", passed, expected=expected, actual=actual)
59
+ if not passed:
60
+ _fail(message, f"Expected {expected!r} (case-insensitive), got {actual!r}.")
61
+
62
+
63
+ def assert_contains(actual: str, expected_substring: str, *, message: str | None = None) -> None:
64
+ """Assert *actual* contains *expected_substring*."""
65
+ passed = expected_substring in actual
66
+ _emit("assert_contains", passed, expected_substring=expected_substring, actual=actual)
67
+ if not passed:
68
+ _fail(message, f"Expected {actual!r} to contain {expected_substring!r}.")
69
+
70
+
71
+ def assert_matches(actual: str, pattern: str, *, message: str | None = None) -> None:
72
+ """Assert *actual* matches the regex *pattern*."""
73
+ passed = re.search(pattern, actual) is not None
74
+ _emit("assert_matches", passed, pattern=pattern, actual=actual)
75
+ if not passed:
76
+ _fail(message, f"Expected {actual!r} to match /{pattern}/.")
77
+
78
+
79
+ def assert_is_empty(actual: str, *, message: str | None = None) -> None:
80
+ """Assert *actual* is an empty string."""
81
+ passed = actual == ""
82
+ _emit("assert_is_empty", passed, actual=actual)
83
+ if not passed:
84
+ _fail(message, f"Expected empty string, got {actual!r}.")
85
+
86
+
87
+ def assert_is_not_empty(actual: str, *, message: str | None = None) -> None:
88
+ """Assert *actual* is a non-empty string."""
89
+ passed = actual != ""
90
+ _emit("assert_is_not_empty", passed, actual=actual)
91
+ if not passed:
92
+ _fail(message, "Expected non-empty string, got empty string.")
93
+
94
+
95
+ def assert_matches_schema(
96
+ actual: object, schema: dict[str, Any], *, message: str | None = None
97
+ ) -> None:
98
+ """Assert *actual* conforms to the given JSON Schema, collecting all errors."""
99
+ import jsonschema
100
+
101
+ validator = jsonschema.Draft7Validator(schema)
102
+ errors = sorted(validator.iter_errors(actual), key=lambda e: list(e.path))
103
+ passed = not errors
104
+ error_messages = [e.message for e in errors]
105
+ _emit(
106
+ "assert_matches_schema",
107
+ passed,
108
+ errors=error_messages,
109
+ schema=json.dumps(schema, indent=2, default=str),
110
+ actual=json.dumps(actual, indent=2, default=str),
111
+ )
112
+ if not passed:
113
+ joined = "; ".join(error_messages)
114
+ _fail(message, f"Schema validation failed with {len(errors)} error(s): {joined}")