Skip to content

Commit aa2b841

Browse files
committed
Add schemathesis tests.
1 parent 9a7be3f commit aa2b841

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/dev.requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ requests
1818
asynctest
1919
psycopg2
2020
pyodbc
21+
schemathesis
2122

2223
# Linting
2324
flake8

tests/test_schemathesis.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
import schemathesis
3+
from fastapi import FastAPI
4+
from schemathesis.specs.openapi.schemas import BaseOpenAPISchema
5+
6+
7+
@pytest.fixture()
8+
def app_schema(client) -> BaseOpenAPISchema:
9+
"""
10+
Get an OpenAPI schema instance for the app created by the `client` fixture.
11+
"""
12+
app: FastAPI = client.app
13+
assert client.app is not None
14+
openapi = app.openapi()
15+
result = schemathesis.from_dict(openapi)
16+
return result
17+
18+
19+
schema = schemathesis.from_pytest_fixture("app_schema")
20+
21+
22+
@schema.parametrize()
23+
def test_api(case):
24+
"""Run tests automatically generated by schemathesis."""
25+
case.call_and_validate()

0 commit comments

Comments
 (0)