pytest-httpchain 0.1.2__tar.gz → 0.2.0__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_httpchain-0.2.0/LICENSE +21 -0
- {pytest_httpchain-0.1.2 → pytest_httpchain-0.2.0}/PKG-INFO +22 -16
- {pytest_httpchain-0.1.2 → pytest_httpchain-0.2.0}/README.md +18 -14
- {pytest_httpchain-0.1.2 → pytest_httpchain-0.2.0}/pyproject.toml +26 -7
- pytest_httpchain-0.2.0/src/pytest_httpchain/__init__.py +23 -0
- pytest_httpchain-0.2.0/src/pytest_httpchain/carrier.py +534 -0
- pytest_httpchain-0.2.0/src/pytest_httpchain/constants.py +26 -0
- pytest_httpchain-0.2.0/src/pytest_httpchain/exceptions.py +30 -0
- {pytest_httpchain-0.1.2 → pytest_httpchain-0.2.0}/src/pytest_httpchain/plugin.py +52 -92
- pytest_httpchain-0.2.0/src/pytest_httpchain/report_formatter.py +69 -0
- pytest_httpchain-0.2.0/src/pytest_httpchain/utils.py +50 -0
- pytest_httpchain-0.1.2/src/pytest_httpchain/__init__.py +0 -0
- pytest_httpchain-0.1.2/src/pytest_httpchain/carrier.py +0 -139
- pytest_httpchain-0.1.2/src/pytest_httpchain/carrier_factory.py +0 -92
- pytest_httpchain-0.1.2/src/pytest_httpchain/constants.py +0 -10
- pytest_httpchain-0.1.2/src/pytest_httpchain/context.py +0 -77
- pytest_httpchain-0.1.2/src/pytest_httpchain/exceptions.py +0 -46
- pytest_httpchain-0.1.2/src/pytest_httpchain/helpers.py +0 -43
- pytest_httpchain-0.1.2/src/pytest_httpchain/request.py +0 -102
- pytest_httpchain-0.1.2/src/pytest_httpchain/response.py +0 -165
- pytest_httpchain-0.1.2/src/pytest_httpchain/stage_executor.py +0 -111
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 aeresov
|
|
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.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytest-httpchain
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: pytest plugin for HTTP testing using JSON files
|
|
5
5
|
Keywords: testing,pytest,requests
|
|
6
6
|
Author: Alexander Eresov
|
|
7
7
|
Author-email: Alexander Eresov <aeresov@gmail.com>
|
|
8
8
|
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
9
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
10
11
|
Classifier: Framework :: Pytest
|
|
11
12
|
Classifier: Intended Audience :: Developers
|
|
@@ -13,11 +14,12 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
13
14
|
Classifier: Programming Language :: Python :: 3
|
|
14
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
16
|
Classifier: Topic :: Software Development :: Testing
|
|
17
|
+
Requires-Dist: httpx[http2]>=0.27.0
|
|
16
18
|
Requires-Dist: pydantic>=2.11.7
|
|
19
|
+
Requires-Dist: pyrate-limiter>=3.0.0
|
|
17
20
|
Requires-Dist: pytest-httpchain-jsonref
|
|
18
21
|
Requires-Dist: pytest-httpchain-models
|
|
19
22
|
Requires-Dist: pytest-order>=1.3.0
|
|
20
|
-
Requires-Dist: rich>=13.7.0
|
|
21
23
|
Requires-Dist: pytest-httpchain-mcp ; extra == 'mcp'
|
|
22
24
|
Requires-Python: >=3.13, <4.0
|
|
23
25
|
Provides-Extra: mcp
|
|
@@ -33,7 +35,7 @@ A pytest plugin for testing HTTP endpoints.
|
|
|
33
35
|
|
|
34
36
|
## Overview
|
|
35
37
|
|
|
36
|
-
`pytest-httpchain` is an integration testing framework for HTTP APIs based on
|
|
38
|
+
`pytest-httpchain` is an integration testing framework for HTTP APIs based on [httpx](https://www.python-httpx.org) lib.
|
|
37
39
|
It aims at helping with common HTTP API testing scenarios, where user needs to make several calls in specific order using data obtained along the way, like auth tokens or resource ids.
|
|
38
40
|
|
|
39
41
|
## Installation
|
|
@@ -60,9 +62,7 @@ The following optional dependencies are available:
|
|
|
60
62
|
|
|
61
63
|
### Pytest integration
|
|
62
64
|
|
|
63
|
-
Most of pytest magic can be used: markers, fixtures, other plugins.
|
|
64
|
-
|
|
65
|
-
> NOTE: parametrization is not yet implemented, therefore `parametrize` marker won't have any effect.
|
|
65
|
+
Most of pytest magic can be used: markers, fixtures, other plugins.
|
|
66
66
|
|
|
67
67
|
### Declarative format
|
|
68
68
|
|
|
@@ -89,6 +89,7 @@ Values from common data context also might be verified during verified/asserted.
|
|
|
89
89
|
- to extract data from HTTP response
|
|
90
90
|
- to verify HTTP response and values in common data context
|
|
91
91
|
- to provide [custom authentication for requests](https://requests.readthedocs.io/en/latest/user/advanced/#custom-authentication)
|
|
92
|
+
- to call in substitution expressions
|
|
92
93
|
|
|
93
94
|
### JMESPath support
|
|
94
95
|
|
|
@@ -114,9 +115,13 @@ def now_utc():
|
|
|
114
115
|
|
|
115
116
|
```json
|
|
116
117
|
{
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
"substitutions": [
|
|
119
|
+
{
|
|
120
|
+
"vars": {
|
|
121
|
+
"user_id": 1
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
],
|
|
120
125
|
"stages": [
|
|
121
126
|
{
|
|
122
127
|
"name": "get_user",
|
|
@@ -131,7 +136,7 @@ def now_utc():
|
|
|
131
136
|
},
|
|
132
137
|
{
|
|
133
138
|
"save": {
|
|
134
|
-
"
|
|
139
|
+
"jmespath": {
|
|
135
140
|
"user_name": "user.name"
|
|
136
141
|
}
|
|
137
142
|
}
|
|
@@ -186,7 +191,7 @@ Scenario we created:
|
|
|
186
191
|
url is assembled using `user_id` variable from common data context
|
|
187
192
|
we create JSON body in place using values from common data context, note that `now_utc` is converted to string in place
|
|
188
193
|
HTTP PUT call with body is made
|
|
189
|
-
we verify the call returned code 200
|
|
194
|
+
we verify the call returned code 200
|
|
190
195
|
- **cleanup**
|
|
191
196
|
finalizing call meant for graceful exit
|
|
192
197
|
`always_run` parameter means this stage will be executed regardless of errors in previous stages
|
|
@@ -238,8 +243,9 @@ The MCP server provides:
|
|
|
238
243
|
|
|
239
244
|
## Thanks
|
|
240
245
|
|
|
241
|
-
`pytest-httpchain` was
|
|
242
|
-
[
|
|
243
|
-
[Pydantic](https://docs.pydantic.dev) keeps
|
|
244
|
-
[
|
|
245
|
-
[pytest-
|
|
246
|
+
`pytest-httpchain` was inspired by [Tavern](https://github.com/taverntesting/tavern) and [pytest-play](https://github.com/davidemoro/pytest-play).
|
|
247
|
+
[httpx](https://www.python-httpx.org) does comms.
|
|
248
|
+
[Pydantic](https://docs.pydantic.dev) keeps structure.
|
|
249
|
+
[simpleeval](https://github.com/danthedeckie/simpleeval) powers templates.
|
|
250
|
+
[pytest-order](https://github.com/pytest-dev/pytest-order) sorts chain.
|
|
251
|
+
[pytest-datadir](https://github.com/gabrielcnr/pytest-datadir) saved me a lot of elbow grease while testing.
|
|
@@ -8,7 +8,7 @@ A pytest plugin for testing HTTP endpoints.
|
|
|
8
8
|
|
|
9
9
|
## Overview
|
|
10
10
|
|
|
11
|
-
`pytest-httpchain` is an integration testing framework for HTTP APIs based on
|
|
11
|
+
`pytest-httpchain` is an integration testing framework for HTTP APIs based on [httpx](https://www.python-httpx.org) lib.
|
|
12
12
|
It aims at helping with common HTTP API testing scenarios, where user needs to make several calls in specific order using data obtained along the way, like auth tokens or resource ids.
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
@@ -35,9 +35,7 @@ The following optional dependencies are available:
|
|
|
35
35
|
|
|
36
36
|
### Pytest integration
|
|
37
37
|
|
|
38
|
-
Most of pytest magic can be used: markers, fixtures, other plugins.
|
|
39
|
-
|
|
40
|
-
> NOTE: parametrization is not yet implemented, therefore `parametrize` marker won't have any effect.
|
|
38
|
+
Most of pytest magic can be used: markers, fixtures, other plugins.
|
|
41
39
|
|
|
42
40
|
### Declarative format
|
|
43
41
|
|
|
@@ -64,6 +62,7 @@ Values from common data context also might be verified during verified/asserted.
|
|
|
64
62
|
- to extract data from HTTP response
|
|
65
63
|
- to verify HTTP response and values in common data context
|
|
66
64
|
- to provide [custom authentication for requests](https://requests.readthedocs.io/en/latest/user/advanced/#custom-authentication)
|
|
65
|
+
- to call in substitution expressions
|
|
67
66
|
|
|
68
67
|
### JMESPath support
|
|
69
68
|
|
|
@@ -89,9 +88,13 @@ def now_utc():
|
|
|
89
88
|
|
|
90
89
|
```json
|
|
91
90
|
{
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
"substitutions": [
|
|
92
|
+
{
|
|
93
|
+
"vars": {
|
|
94
|
+
"user_id": 1
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
],
|
|
95
98
|
"stages": [
|
|
96
99
|
{
|
|
97
100
|
"name": "get_user",
|
|
@@ -106,7 +109,7 @@ def now_utc():
|
|
|
106
109
|
},
|
|
107
110
|
{
|
|
108
111
|
"save": {
|
|
109
|
-
"
|
|
112
|
+
"jmespath": {
|
|
110
113
|
"user_name": "user.name"
|
|
111
114
|
}
|
|
112
115
|
}
|
|
@@ -161,7 +164,7 @@ Scenario we created:
|
|
|
161
164
|
url is assembled using `user_id` variable from common data context
|
|
162
165
|
we create JSON body in place using values from common data context, note that `now_utc` is converted to string in place
|
|
163
166
|
HTTP PUT call with body is made
|
|
164
|
-
we verify the call returned code 200
|
|
167
|
+
we verify the call returned code 200
|
|
165
168
|
- **cleanup**
|
|
166
169
|
finalizing call meant for graceful exit
|
|
167
170
|
`always_run` parameter means this stage will be executed regardless of errors in previous stages
|
|
@@ -213,8 +216,9 @@ The MCP server provides:
|
|
|
213
216
|
|
|
214
217
|
## Thanks
|
|
215
218
|
|
|
216
|
-
`pytest-httpchain` was
|
|
217
|
-
[
|
|
218
|
-
[Pydantic](https://docs.pydantic.dev) keeps
|
|
219
|
-
[
|
|
220
|
-
[pytest-
|
|
219
|
+
`pytest-httpchain` was inspired by [Tavern](https://github.com/taverntesting/tavern) and [pytest-play](https://github.com/davidemoro/pytest-play).
|
|
220
|
+
[httpx](https://www.python-httpx.org) does comms.
|
|
221
|
+
[Pydantic](https://docs.pydantic.dev) keeps structure.
|
|
222
|
+
[simpleeval](https://github.com/danthedeckie/simpleeval) powers templates.
|
|
223
|
+
[pytest-order](https://github.com/pytest-dev/pytest-order) sorts chain.
|
|
224
|
+
[pytest-datadir](https://github.com/gabrielcnr/pytest-datadir) saved me a lot of elbow grease while testing.
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pytest-httpchain"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "pytest plugin for HTTP testing using JSON files"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13,<4.0"
|
|
7
7
|
authors = [{ name = "Alexander Eresov", email = "aeresov@gmail.com" }]
|
|
8
8
|
dependencies = [
|
|
9
|
+
"httpx[http2]>=0.27.0",
|
|
9
10
|
"pydantic>=2.11.7",
|
|
11
|
+
"pyrate-limiter>=3.0.0",
|
|
10
12
|
"pytest-httpchain-jsonref",
|
|
11
13
|
"pytest-httpchain-models",
|
|
12
14
|
"pytest-order>=1.3.0",
|
|
13
|
-
"rich>=13.7.0",
|
|
14
15
|
]
|
|
15
16
|
keywords = ["testing", "pytest", "requests"]
|
|
16
17
|
license = "MIT"
|
|
18
|
+
license-files = ["LICENSE"]
|
|
17
19
|
classifiers = [
|
|
18
20
|
"Development Status :: 5 - Production/Stable",
|
|
19
21
|
"Framework :: Pytest",
|
|
@@ -31,9 +33,10 @@ mcp = ["pytest-httpchain-mcp"]
|
|
|
31
33
|
dev = [
|
|
32
34
|
"flask-httpauth>=4.8.0",
|
|
33
35
|
"http-server-mock>=1.7",
|
|
34
|
-
"pytest-xdist>=3.8.0",
|
|
35
|
-
"responses>=0.25.7",
|
|
36
36
|
"ruff>=0.12.1",
|
|
37
|
+
"pytest-cov>=6.0.0",
|
|
38
|
+
"coverage[toml]>=7.0",
|
|
39
|
+
"pytest-datadir>=1.7.2",
|
|
37
40
|
]
|
|
38
41
|
docs = [
|
|
39
42
|
"mkdocs>=1.6.1",
|
|
@@ -43,7 +46,7 @@ docs = [
|
|
|
43
46
|
]
|
|
44
47
|
|
|
45
48
|
[tool.uv]
|
|
46
|
-
default-groups = ["docs"]
|
|
49
|
+
default-groups = ["dev", "docs"]
|
|
47
50
|
|
|
48
51
|
[tool.uv.workspace]
|
|
49
52
|
members = ["packages/*"]
|
|
@@ -85,10 +88,10 @@ ignore = []
|
|
|
85
88
|
[tool.ruff.lint.isort]
|
|
86
89
|
known-first-party = ["tests", "utils"]
|
|
87
90
|
|
|
88
|
-
[tool.pytest
|
|
91
|
+
[tool.pytest]
|
|
92
|
+
minversion = "9.0"
|
|
89
93
|
log_cli = true
|
|
90
94
|
log_cli_level = "INFO"
|
|
91
|
-
# testpaths = ["tests"]
|
|
92
95
|
norecursedirs = ["examples"]
|
|
93
96
|
pytester_example_dir = "tests/integration/examples"
|
|
94
97
|
addopts = ["--log-disable=werkzeug", "--import-mode=importlib"]
|
|
@@ -110,3 +113,19 @@ reportMissingTypeStubs = false
|
|
|
110
113
|
reportExplicitAny = false
|
|
111
114
|
typeCheckingMode = "off"
|
|
112
115
|
pythonPlatform = "Linux"
|
|
116
|
+
|
|
117
|
+
[tool.coverage.run]
|
|
118
|
+
source = [
|
|
119
|
+
"src",
|
|
120
|
+
"packages/pytest-httpchain-jsonref/src",
|
|
121
|
+
"packages/pytest-httpchain-templates/src",
|
|
122
|
+
"packages/pytest-httpchain-mcp/src",
|
|
123
|
+
"packages/pytest-httpchain-models/src",
|
|
124
|
+
"packages/pytest-httpchain-userfunc/src",
|
|
125
|
+
]
|
|
126
|
+
branch = true
|
|
127
|
+
|
|
128
|
+
[tool.coverage.report]
|
|
129
|
+
precision = 2
|
|
130
|
+
show_missing = true
|
|
131
|
+
skip_covered = false
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""pytest-httpchain: Declarative HTTP API integration testing.
|
|
2
|
+
|
|
3
|
+
This pytest plugin enables declarative HTTP API integration testing using JSON files.
|
|
4
|
+
Test scenarios are defined with $ref support, template expressions ({{ expr }}),
|
|
5
|
+
and multi-stage request chaining.
|
|
6
|
+
|
|
7
|
+
Example test file (test_api.http.json):
|
|
8
|
+
{
|
|
9
|
+
"description": "API integration test",
|
|
10
|
+
"stages": [
|
|
11
|
+
{
|
|
12
|
+
"name": "Get user",
|
|
13
|
+
"request": {
|
|
14
|
+
"method": "GET",
|
|
15
|
+
"url": "https://api.example.com/users/1"
|
|
16
|
+
},
|
|
17
|
+
"response": [
|
|
18
|
+
{"verify": {"status": 200}}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
"""
|