Skip to main content

pytest-graphql

Schema-aware GraphQL API testing for pytest.

The client reads your schema, chooses the fields to ask for, checks each call before it sends anything, and returns responses that read like Python objects. A test has no query text in it, so it is easy to read, and a schema change does not mean editing query strings by hand.

Documentation: https://skhomenko.github.io/pytest-graphql/

Quickstart

Install the package with its pytest extra:

pip install "pytest-graphql[pytest]"

Tell pytest where your GraphQL endpoint is:

# pytest.ini
[pytest]
gql_url = http://localhost:8000/graphql

Write a test. The gql fixture is a client that has already read your schema:

def test_user_has_a_name(gql):
    user = gql.query("user", id="u1")
    assert user.name == "Ada Lovelace"

Run pytest. The client chooses the fields to ask for, so the test contains no query text.

Features

  • Fields chosen for you. Auto-selection builds the selection set from the schema, and fields= takes over when you need exact fields. Selections
  • Responses that read like Python. Attribute access, snake_case names, lists with helpers, and an error for a field that is not there. Responses
  • Assertions with a readable diff. Plain assert, partial matchers such as gql.expect.User(...), and list helpers. Assertions
  • Errors that raise. A response with errors raises, and gql.expect_error() is for the test that expects one. Errors
  • Seeded fake input. gql.fake.<InputType>() repeats from run to run, and unique() marks a field that must differ. Factory
  • Identity. Clone a client as another user, write your own Auth, and refresh a token. Authentication
  • Polling. gql.wait_until() repeats a query with a deadline and a backoff. Polling
  • Reports with the calls in them. A failed test lists its calls, hides the headers and variables that you list as secrets, and ends with a curl line that repeats the failed call. Diagnostics
  • Open to change. Replace the transport, load the schema from a file, register custom scalars, add middleware, or use one of six pytest hooks. Extending
  • No pytest needed. The core imports no pytest. build_client() works in unittest, in scripts and in a shell. Using without pytest
  • Parallel runs. The plugin works with pytest-xdist. Cookbook

More documentation

Install

pip install pytest-graphql

The required dependencies are graphql-core, httpx and certifi. pytest is optional, so the client can be used outside a test suite. Add the extra when you use the plugin:

pip install "pytest-graphql[pytest]"

Supported versions

Python 3.10 through 3.14, graphql-core 3.2 and 3.3, and pytest 7.4 or newer when the pytest extra is installed. CI tests a representative sample of that range rather than the whole cross product.

Status

Version 0.x. The API may change between minor versions, and the changelog records every change. An on-disk schema cache, async clients, subscriptions and file uploads are not part of 0.1.0.

License

MIT. See https://github.com/skhomenko/pytest-graphql/blob/main/LICENSE

Metadata

Release files for pytest-graphql 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-graphql 0.1.0
File Size Uploaded
pytest_graphql-0.1.0.tar.gz 793.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-graphql 0.1.0
File Interpreter ABI Platform
pytest_graphql-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / pytest_graphql-0.1.0.tar.gz

Download URL pytest_graphql-0.1.0.tar.gz
Size 793.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2d21a40606cd5ee0e8df1f7d343730b72e7b80523406a26e4d457db8ac90cfb8
BLAKE2b-256 checksum
How to use checksums
47e88a0d217089a8e624ae22962b0f30b43b93751e25670004c23820c49d35b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / pytest_graphql-0.1.0-py3-none-any.whl

Download URL pytest_graphql-0.1.0-py3-none-any.whl
Size 276.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6008a43216b49f30db8e442aba24154e2cda21de7a9da55a2f3c346f758dd722
BLAKE2b-256 checksum
How to use checksums
3a699b2a2301cf449dbabbcb15dc0907f1b153623535a1eca227a2babb4d8769
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page