Description
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
Schemathesis alternatives and similar packages
Based on the "Testing" category.
Alternatively, view Schemathesis alternatives based on common mentions on social networks and blogs.
-
pytest
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing -
Robot Framework
Generic automation framework for acceptance testing and RPA -
PyAutoGUI
A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard. -
Moto
A library that allows you to easily mock out tests based on AWS infrastructure. -
hypothesis
Hypothesis is a powerful, flexible, and easy to use library for property-based testing. -
responses
A utility for mocking out the Python Requests library. -
Mimesis
Mimesis is a robust data generator for Python, capable of rapidly producing large volumes of synthetic data for various use cases. -
tox
Command line driven CI frontend and development task automation tool. -
VCR.py
Automatically mock your HTTP interactions to simplify and speed up testing -
httpretty
Intercept HTTP requests at the Python socket level. Fakes the whole socket module -
fake2db
create custom test databases that are populated with fake data -
Selenium Wire
Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser. -
mixer
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects. -
mamba
The definitive testing tool for Python. Born under the banner of Behavior Driven Development (BDD). -
Mocket
a socket mock framework - for all kinds of socket animals, web-clients included -
sentry-telegram
Plugin for Sentry which allows sending notification via Telegram messenger. -
picka
pip install picka - Picka is a python based data generation and randomization module which aims to increase coverage by increasing the amount of tests you _dont_ have to write by hand. -
python-libfaketime
A fast time mocking alternative to freezegun that wraps libfaketime. -
Python Testing Crawler
A crawler for automated functional testing of a web application -
Mock Generator
A tool to auto generate the basic mocks and asserts for faster unit testing -
Pytest Mock Generator
A pytest fixture wrapper for https://pypi.org/project/mock-generator -
pytest-fastapi-deps
This library allows you to easily replace FastAPI dependencies in your tests. Regular mocking techniques do not work due to the inner working of FastAPI.
TestGPT | Generating meaningful tests for busy devs
* 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?
README
Schemathesis
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
NOTE: The library is WIP, the API is a subject to change.
Usage
To generate test cases for your schema you need:
- Create a parametrizer;
- Wrap a test with
Parametrizer.parametrize
method - Provide a client and url of a running application instance
import 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:
method
formatted_path
headers
query
body
For 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):
...
Documentation
For full documentation, please see [https://schemathesis.readthedocs.io/en/latest/]
Or you can look at the [docs/] directory in the repository.
Python support
Schemathesis supports Python 3.6, 3.7 and 3.8.
License
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.