Back to all posts
Releases

November in Schemathesis

Schemathesis generates test requests from your OpenAPI or GraphQL schema and reports server errors and responses that break it. Docs | GitHub

Highlights from 4.32.6 to 4.34.3: gRPC fuzzing, a coverage phase for GraphQL, testing Python apps without a server, more of Open API 3.2, and extensions with their own settings.

gRPC fuzzing (4.33.0)

Schemathesis tests unary gRPC methods: it generates request messages from the service descriptors, calls the server and checks the responses. Point it at a server with reflection enabled:

Bash
uvx --from 'schemathesis[grpc]' schemathesis run grpc://localhost:50051

A server without reflection takes a descriptor set built with buf or protoc: schemathesis run api.binpb --url grpc://localhost:50051. Failures show the gRPC status and a grpcurl command to reproduce the call. See Testing gRPC Services.

Coverage phase for GraphQL (4.33.0)

GraphQL runs get the coverage phase: each case changes one argument or input field of a fixed valid query, or adds one field to its selection, up to three levels deep. For this schema:

GraphQL
enum Genre { DRAMA COMEDY }

type Query {
  books(limit: Int!, genre: Genre): [Book]
}

# Valid
books(limit: 0)
books(limit: -2147483648)
books(limit: 0, genre: null)
books(limit: 0, genre: DRAMA)

# Invalid
books
books(limit: "a")
books(limit: 2147483648)
books(limit: 0, genre: invalid)

response_schema_conformance checks GraphQL data for missing, unrequested and mistyped fields.

Python apps without a server (4.34.0)

st run tests an ASGI or WSGI application in the same process when you name it with --app:

Bash
uvx --with fastapi schemathesis run /openapi.json --app project.asgi:app

An exception raised by a handler is reported as a Server error with the traceback of your code. Put app = "project.asgi:app" in schemathesis.toml to drop the option. See Python apps.

Extended Open API 3.2 support (4.33.0, 4.34.0)

Schemathesis tests more of what Open API 3.2 describes:

  • additionalOperations with custom methods like COPY or PURGE;
  • itemSchema for text/event-stream and multipart/mixed request bodies, and for JSON Lines and JSON Text Sequence responses;
  • application/jsonl, x-ndjson and json-seq request bodies, one JSON record per line;
  • XML nodeType, cookie parameters with style: cookie, and body examples given as serializedValue.

Extensions with their own settings (4.34.0)

New setup and teardown hooks run once around testing in st run and pytest. An extension is a class whose methods are hooks, with its own table in schemathesis.toml. This one seeds test data before testing and removes it afterwards:

Python
# test_data.py
import schemathesis


@schemathesis.extension("test-data")
class TestData:
    def __init__(self, settings):
        self.orders = settings.get("orders", 10)

    def setup(self, ctx, schema):
        seed = schema["/test-data/seed"]["POST"]
        for _ in range(self.orders):
            seed.Case().call()

    def teardown(self, ctx, schema):
        schema["/test-data/reset"]["POST"].Case().call()
TOML
# schemathesis.toml
hooks = "test_data"

[extensions.test-data]
orders = 50

teardown runs even when testing fails or is interrupted. hooks also takes a list of modules, loaded in order.

Also

Error feedback learns integer, hex and ObjectId formats from Java and MongoDB parse errors, from-operation dictionaries fill from responses (#5751), and Case.reapply_auth() refreshes expired tokens.

Upgrade with pip install -U schemathesis, or uv tool upgrade schemathesis.

The changelog lists 310 fixes. If you test a gRPC service, open an issue with what Schemathesis missed or got wrong.

All posts Questions? Join our Discord