Schemathesis is a tool that generates test cases for your Open API / Swagger schemas.
The main goal is to bring property-based testing to web applications and verify if all values allowed by the schema are processed correctly by the application.
Empowered by Hypothesis, hypothesis_jsonschema, and pytest.
Supported specification versions:
- Swagger 2.0
- Open API 3.0.x
Based on the "Testing" category.
Alternatively, view Schemathesis alternatives based on common mentions on social networks and blogs.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Schemathesis or a related project?
Schemathesis is a tool that generates test cases for your Open API / Swagger schemas.
The main goal is to bring property-based testing to web applications and verify if all values allowed by the schema are processed correctly by the application.
Empowered by Hypothesis, hypothesis_jsonschema and pytest.
Supported specification versions:
NOTE: The library is WIP, the API is a subject to change.
To generate test cases for your schema you need:
Parametrizer.parametrize methodimport pytest
import requests
from schemathesis import Parametrizer
schema = Parametrizer.from_path("path/to/schema.yaml")
@pytest.fixture(scope="session")
def client():
with requests.Session() as session:
yield session
@schema.parametrize()
def test_users_endpoint(client, case):
url = "http://0.0.0.0:8080" + case.formatted_path
response = client.request(
case.method,
url,
params=case.query,
json=case.body
)
assert response.status_code == 200
Each wrapped test will have the case fixture, that represents a
hypothesis test case.
Case consists of:
methodformatted_pathheadersquerybodyFor each schemathesis will create hypothesis strategies which will
generate bunch of random inputs acceptable by schema.
This data could be used to verify that your application works in the way
as described in the schema or that schema describes expected behaviour.
For example the data could be send against running app container via
requests and response is checked for an expected status code or error
message.
To limit the number of examples you could use hypothesis.settings decorator on your test functions:
from hypothesis import settings
@settings(max_examples=5)
def test_something(client, case):
...
For full documentation, please see [https://schemathesis.readthedocs.io/en/latest/]
Or you can look at the [docs/] directory in the repository.
Schemathesis supports Python 3.6, 3.7 and 3.8.
The code in this project is licensed under MIT license.
By contributing to schemathesis, you agree that your contributions
will be licensed under its MIT license.
*Note that all licence references and agreements mentioned in the Schemathesis README section above
are relevant to that project's source code only.
Do not miss the trending, packages, news and articles with our weekly report.