diff --git a/tests/dev.requirements.txt b/tests/dev.requirements.txt index 9182cdd..2132a1b 100644 --- a/tests/dev.requirements.txt +++ b/tests/dev.requirements.txt @@ -12,12 +12,15 @@ gino-starlette==0.1.1 asyncpg # Testing -pytest +openapi-spec-validator +pytest; python_version != '3.9' +pytest !=7.0.0; python_version == '3.9' pytest-virtualenv requests asynctest psycopg2 pyodbc +schemathesis # Linting flake8 diff --git a/tests/test_schemathesis.py b/tests/test_schemathesis.py new file mode 100644 index 0000000..813b284 --- /dev/null +++ b/tests/test_schemathesis.py @@ -0,0 +1,25 @@ +import pytest +import schemathesis +from fastapi import FastAPI +from schemathesis.specs.openapi.schemas import BaseOpenAPISchema + + +@pytest.fixture() +def app_schema(client) -> BaseOpenAPISchema: + """ + Get an OpenAPI schema instance for the app created by the `client` fixture. + """ + app: FastAPI = client.app + assert client.app is not None + openapi = app.openapi() + result = schemathesis.from_dict(openapi) + return result + + +schema = schemathesis.from_pytest_fixture("app_schema") + + +@schema.parametrize() +def test_api(case, client): + """Run tests automatically generated by schemathesis.""" + case.call_and_validate(session=client)