pytest-openapi 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sinan Ozel
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,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-openapi
3
+ Version: 0.1.0
4
+ Author-email: Sinan Ozel <coding@sinan.slmail.me>
5
+ License: MIT License
6
+
7
+ Copyright (c) 2025 Sinan Ozel
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Project-URL: Homepage, https://github.com/sinan-ozel/pytest-openapi
28
+ Project-URL: Issues, https://github.com/sinan-ozel/pytest-openapi/issues
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: pytest>=7.0.0
35
+ Requires-Dist: requests>=2.31.0
36
+ Requires-Dist: exrex>=0.11.0
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest>=7.0.0; extra == "test"
39
+ Requires-Dist: pytest-depends>=1.0.1; extra == "test"
40
+ Requires-Dist: pytest-mock>=3.14.0; extra == "test"
41
+ Requires-Dist: httpx>=0.28.1; extra == "test"
42
+ Provides-Extra: dev
43
+ Requires-Dist: isort>=5.12.0; extra == "dev"
44
+ Requires-Dist: ruff>=0.12.11; extra == "dev"
45
+ Requires-Dist: black>=24.0.0; extra == "dev"
46
+ Requires-Dist: docformatter>=1.7.5; extra == "dev"
47
+ Provides-Extra: docs
48
+ Requires-Dist: mkdocs-material>=9.0.0; extra == "docs"
49
+ Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "docs"
50
+ Provides-Extra: publish
51
+ Requires-Dist: packaging>=25.0; extra == "publish"
52
+ Dynamic: license-file
53
+
54
+ # 🧪 OpenAPI Contract Tester
55
+
56
+ An opinionated, lightweight **black-box contract tester** against a **live API** using its OpenAPI specification as the source of truth.
57
+
58
+ This tool validates OpenAPI quality, generates test cases from schemas, and verifies that real HTTP responses match the contract.
59
+ This "certifies" that the documentation is complete with descriptions, example, and schema, and that the endpoint behaves as the documentation suggests.
60
+
61
+ ## Why?
62
+
63
+ This package tries to simulate the frustrations of API users, as consumers.
64
+ With the rise of "agents", this type of documentation-code match became even
65
+ more important, because LLMs really have trouble choosing tools or using them
66
+ properly when they do not work as intended.
67
+
68
+ ## ✨ What it does
69
+
70
+ ### ▶️ Quick Example
71
+
72
+ ![Swagger POST endpoint /email](swagger-screenshot-1.png)
73
+
74
+ ```bash
75
+ pytest --openapi=http://localhost:8000
76
+ ```
77
+
78
+ ```
79
+ Test #10 ✅
80
+ POST /email
81
+ Requested:
82
+ {
83
+ "body": "Lorem ipsum dolor sit amet",
84
+ "from": "Lorem ipsum dolor sit amet",
85
+ "subject": "Lorem ipsum dolor sit amet",
86
+ "to": "Test!@#$%^&*()_+-=[]{}|;:<>?,./`~"
87
+ }
88
+
89
+ Expected 201
90
+ {
91
+ "body": "Hi Bob, how are you?",
92
+ "from": "alice@example.com",
93
+ "id": 1,
94
+ "subject": "Hello",
95
+ "to": "bob@example.com"
96
+ }
97
+
98
+ Actual 201
99
+ {
100
+ "body": "Lorem ipsum dolor sit amet",
101
+ "from": "Lorem ipsum dolor sit amet",
102
+ "id": 10,
103
+ "subject": "Lorem ipsum dolor sit amet",
104
+ "to": "Test!@#$%^&*()_+-=[]{}|;:<>?,./`~"
105
+ }
106
+
107
+ ```
108
+ Generates multiple QA tests.
109
+
110
+ ✔️ Validates OpenAPI request/response definitions
111
+ ✔️ Enforces schema field descriptions
112
+ ✔️ Generates test cases from schemas, checks response codes and types in the response
113
+ ✔️ Tests the exanples
114
+ ✔️ Tests **GET / POST / PUT / DELETE** endpoints
115
+ ✔️ Compares live responses against examples
116
+ ✔️ Produces a readable test report
117
+
118
+
119
+ # ▶️ Detailed Example
120
+
121
+ ## Install
122
+ ```bash
123
+ pip install pytest-openapi
124
+ ```
125
+
126
+ ## Run
127
+
128
+ Say that you have a service running at port `8000` on `localhost`. Then, run:
129
+
130
+ ```bash
131
+ pytest --openapi=http://localhost:8000
132
+ ```
133
+
134
+ ## Server
135
+ See here an example server - `email-server`: [tests/test_servers/email_server/server.py](tests/test_servers/email_server/server.py)
136
+
137
+ ## Resulting Tests
138
+
139
+ [tests/test_servers/email_server/email_test_output.txt](tests/test_servers/email_server/email_test_output.txt)
140
+
141
+ # Future Plans / TODO
142
+
143
+ This is a work in progress.
144
+ - [ ] A check that the example matches the schema
145
+ - [ ] Ask that 400 responses be in the documentation.
146
+ - [ ] A check for regexp and email formats.
147
+ - [ ] Extra checks from 200 or 201 messages with missing keys to see 400 messages.
148
+ - [ ] Option to turn off the description requirement.
149
+
150
+ ## In Consideration
151
+ - [ ] Use LLM-as-a-judge to assess the error messages and check their spelling.
152
+
153
+ # Contributing
154
+ Contributions are welcome!
155
+
156
+ The only requirement is 🐳 Docker.
157
+
158
+ Test are containerized, run them using the VS Code task `test`. If you don't want to use VS Code, the command is `docker compose -f ./tests/docker-compose.yaml --project-directory ./tests up --build --abort-on-container-exit --exit-code-from test`. Run this before making a PR, please.
159
+
160
+ There is also a development environment for VS Code, if you need it. On this environment, you can run the task `run-mock-server` to run one of the [mock servers](tests/test_servers) and see the output.
161
+
162
+ You can add your own mock server, and then add integration tests. Just follow the same pattern as every test to make a call - `subprocess.run('pytest', '--openapi=http://your-server:8000`.
163
+
164
+ Please reformat and lint before making a PR. The VS Task is `lint`, and if you don't want to use VS Code, the command is: `docker compose -f ./lint/docker-compose.yaml --project-directory ./lint up --build --abort-on-container-exit --exit-code-from linter`. Run this before making a PR, please.
165
+
166
+ If you add a functionality, please add to the the documentation.
167
+
168
+ Please submit a pull request or open an issue for any bugs or feature requests.
169
+
170
+ The moment your PR is merged, you get a dev release. You can then set up the version number to use your changes.
171
+
172
+ # License
173
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
174
+
@@ -0,0 +1,121 @@
1
+ # 🧪 OpenAPI Contract Tester
2
+
3
+ An opinionated, lightweight **black-box contract tester** against a **live API** using its OpenAPI specification as the source of truth.
4
+
5
+ This tool validates OpenAPI quality, generates test cases from schemas, and verifies that real HTTP responses match the contract.
6
+ This "certifies" that the documentation is complete with descriptions, example, and schema, and that the endpoint behaves as the documentation suggests.
7
+
8
+ ## Why?
9
+
10
+ This package tries to simulate the frustrations of API users, as consumers.
11
+ With the rise of "agents", this type of documentation-code match became even
12
+ more important, because LLMs really have trouble choosing tools or using them
13
+ properly when they do not work as intended.
14
+
15
+ ## ✨ What it does
16
+
17
+ ### ▶️ Quick Example
18
+
19
+ ![Swagger POST endpoint /email](swagger-screenshot-1.png)
20
+
21
+ ```bash
22
+ pytest --openapi=http://localhost:8000
23
+ ```
24
+
25
+ ```
26
+ Test #10 ✅
27
+ POST /email
28
+ Requested:
29
+ {
30
+ "body": "Lorem ipsum dolor sit amet",
31
+ "from": "Lorem ipsum dolor sit amet",
32
+ "subject": "Lorem ipsum dolor sit amet",
33
+ "to": "Test!@#$%^&*()_+-=[]{}|;:<>?,./`~"
34
+ }
35
+
36
+ Expected 201
37
+ {
38
+ "body": "Hi Bob, how are you?",
39
+ "from": "alice@example.com",
40
+ "id": 1,
41
+ "subject": "Hello",
42
+ "to": "bob@example.com"
43
+ }
44
+
45
+ Actual 201
46
+ {
47
+ "body": "Lorem ipsum dolor sit amet",
48
+ "from": "Lorem ipsum dolor sit amet",
49
+ "id": 10,
50
+ "subject": "Lorem ipsum dolor sit amet",
51
+ "to": "Test!@#$%^&*()_+-=[]{}|;:<>?,./`~"
52
+ }
53
+
54
+ ```
55
+ Generates multiple QA tests.
56
+
57
+ ✔️ Validates OpenAPI request/response definitions
58
+ ✔️ Enforces schema field descriptions
59
+ ✔️ Generates test cases from schemas, checks response codes and types in the response
60
+ ✔️ Tests the exanples
61
+ ✔️ Tests **GET / POST / PUT / DELETE** endpoints
62
+ ✔️ Compares live responses against examples
63
+ ✔️ Produces a readable test report
64
+
65
+
66
+ # ▶️ Detailed Example
67
+
68
+ ## Install
69
+ ```bash
70
+ pip install pytest-openapi
71
+ ```
72
+
73
+ ## Run
74
+
75
+ Say that you have a service running at port `8000` on `localhost`. Then, run:
76
+
77
+ ```bash
78
+ pytest --openapi=http://localhost:8000
79
+ ```
80
+
81
+ ## Server
82
+ See here an example server - `email-server`: [tests/test_servers/email_server/server.py](tests/test_servers/email_server/server.py)
83
+
84
+ ## Resulting Tests
85
+
86
+ [tests/test_servers/email_server/email_test_output.txt](tests/test_servers/email_server/email_test_output.txt)
87
+
88
+ # Future Plans / TODO
89
+
90
+ This is a work in progress.
91
+ - [ ] A check that the example matches the schema
92
+ - [ ] Ask that 400 responses be in the documentation.
93
+ - [ ] A check for regexp and email formats.
94
+ - [ ] Extra checks from 200 or 201 messages with missing keys to see 400 messages.
95
+ - [ ] Option to turn off the description requirement.
96
+
97
+ ## In Consideration
98
+ - [ ] Use LLM-as-a-judge to assess the error messages and check their spelling.
99
+
100
+ # Contributing
101
+ Contributions are welcome!
102
+
103
+ The only requirement is 🐳 Docker.
104
+
105
+ Test are containerized, run them using the VS Code task `test`. If you don't want to use VS Code, the command is `docker compose -f ./tests/docker-compose.yaml --project-directory ./tests up --build --abort-on-container-exit --exit-code-from test`. Run this before making a PR, please.
106
+
107
+ There is also a development environment for VS Code, if you need it. On this environment, you can run the task `run-mock-server` to run one of the [mock servers](tests/test_servers) and see the output.
108
+
109
+ You can add your own mock server, and then add integration tests. Just follow the same pattern as every test to make a call - `subprocess.run('pytest', '--openapi=http://your-server:8000`.
110
+
111
+ Please reformat and lint before making a PR. The VS Task is `lint`, and if you don't want to use VS Code, the command is: `docker compose -f ./lint/docker-compose.yaml --project-directory ./lint up --build --abort-on-container-exit --exit-code-from linter`. Run this before making a PR, please.
112
+
113
+ If you add a functionality, please add to the the documentation.
114
+
115
+ Please submit a pull request or open an issue for any bugs or feature requests.
116
+
117
+ The moment your PR is merged, you get a dev release. You can then set up the version number to use your changes.
118
+
119
+ # License
120
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
121
+
@@ -0,0 +1,71 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pytest-openapi"
7
+ dynamic = ["version"]
8
+ description = ""
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Sinan Ozel", email = "coding@sinan.slmail.me" },
12
+ ]
13
+ license = { file = "LICENSE" }
14
+ dependencies = [
15
+ "pytest>=7.0.0",
16
+ "requests>=2.31.0",
17
+ "exrex>=0.11.0",
18
+ ]
19
+ classifiers = [
20
+ "Programming Language :: Python :: 3",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: OS Independent"
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+ test = [
27
+ "pytest>=7.0.0", # For running tests
28
+ "pytest-depends>=1.0.1", # For test dependency management
29
+ "pytest-mock>=3.14.0", # For mocking in tests
30
+ "httpx>=0.28.1", # To make more complex calls, such as streaming.
31
+ ]
32
+
33
+ dev = [
34
+ "isort>=5.12.0", # For import sorting
35
+ "ruff>=0.12.11", # For linting
36
+ "black>=24.0.0", # For code formatting (Black)
37
+ "docformatter>=1.7.5", # For formatting docstrings
38
+ ]
39
+
40
+ docs = [
41
+ "mkdocs-material>=9.0.0", # Material theme for MkDocs
42
+ "mkdocstrings[python]>=0.24.0", # API documentation from docstrings
43
+ ]
44
+
45
+ publish = [
46
+ "packaging>=25.0",
47
+ ]
48
+
49
+ [tool.ruff]
50
+ line-length = 80
51
+
52
+ [tool.ruff.lint.per-file-ignores]
53
+ "**/test_*.py" = ["RUF001"]
54
+
55
+ [tool.black]
56
+ line-length = 80
57
+ target-version = ['py311']
58
+
59
+ [tool.isort]
60
+ profile = "black"
61
+ line_length = 80
62
+
63
+ [tool.setuptools.dynamic]
64
+ version = { attr = "pytest_openapi.__version__" }
65
+
66
+ [project.urls]
67
+ Homepage = "https://github.com/sinan-ozel/pytest-openapi"
68
+ Issues = "https://github.com/sinan-ozel/pytest-openapi/issues"
69
+
70
+ [project.entry-points.pytest11]
71
+ pytest_openapi = "pytest_openapi.plugin"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"