This release is a pre-release and may not be stable for production use.
pytest-graphql
Schema-aware GraphQL API testing for pytest.
Status
Alpha. This release contains a working client, an httpx transport, a response
model and one pytest fixture. The API may still change before 0.1.0.
What 0.1.0a1 contains:
GraphQLClientandbuild_client(). The client reads your schema and builds the selection set for an operation. By default it checks the operation against the schema before it sends anything, andvalidate=Falseturns that check off. Arguments and fields are snake_case in Python and use the schema's own names on the wire.- An
httpxtransport with explicit timeout, retry and response size limits. With this transport, tests share one connection pool and each client keeps its own cookie jar. A transport you supply manages its own connections and cookies. - A response model. Failures carry a redacted summary of the request.
RequestInfo.as_curl(), available to middleware, renders acurlcommand that reproduces a request, with credentials replaced by placeholders. - Bearer and header auth, and request middleware.
- The pytest fixtures
gql,gql_urlandgql_transport, and the--gql-urlflag. The schema loads once per session, and each test gets its own client.
Not in this release yet: ini options, environment variables and hooks, response matching, fake data, error assertions and polling.
The changelog records what each release contains: https://github.com/skhomenko/pytest-graphql/blob/main/CHANGELOG.md
Usage
With pytest, pass the endpoint on the command line:
pytest --gql-url=http://localhost:8000/graphql
def test_user_has_a_name(gql):
user = gql.query("user", id="123")
assert user.name
For a URL known only at run time, override the gql_url fixture in your
conftest.py. The --gql-url flag still wins when both are given.
Without pytest, use build_client(), and close the client when you are done:
from pytest_graphql import build_client
with build_client(url="http://localhost:8000/graphql") as gql:
user = gql.query("user", id="123")
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:
pip install "pytest-graphql[pytest]"
Supported versions
Python 3.10 through 3.14, with 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.
License
MIT. See https://github.com/skhomenko/pytest-graphql/blob/main/LICENSE
Metadata
Release files for pytest-graphql 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_graphql-0.1.0a1.tar.gz | 383.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_graphql-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 529.1 kB
Release files / pytest_graphql-0.1.0a1.tar.gz
| Download URL | pytest_graphql-0.1.0a1.tar.gz |
|---|---|
| Size | 383.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32a185ba306c1bac1083dbe3f5b60bcabd6ede4478f5f279d2dfbefaf2a8926b
|
|
BLAKE2b-256 checksum How to use checksums |
9c9e121dad266adc97b3530c5f6fab4c04c5361921890e0d388a10ebcf55eda4
|
| 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 3, 2026.
Transparency logRelease files / pytest_graphql-0.1.0a1-py3-none-any.whl
| Download URL | pytest_graphql-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 145.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25b6b40619b0c9f8cdcba806f47ed83795c2a8a738a4de89f656326a1325f953
|
|
BLAKE2b-256 checksum How to use checksums |
db4f7518ceba5485fc0e3457a89b8e322a092e944253c79e109cee59720806e5
|
| 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 3, 2026.
Transparency log