Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e302c24

Browse files
committedSep 4, 2019
Add pytest-benchmark and port introspectionFromSchema-benchmark.js
1 parent da6d040 commit e302c24

File tree

7 files changed

+13207
-78
lines changed

7 files changed

+13207
-78
lines changed
 

‎poetry.lock

Lines changed: 23 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ sphinx_rtd_theme = ">=0.4"
4545
check-manifest = ">=0.39"
4646
bump2version = ">=0.5"
4747
tox = "^3.13"
48+
pytest-benchmark = "^3.2"
4849

4950
[tool.black]
5051
target-version = ['py36', 'py37', 'py38']

‎setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ python-tag = py3
33

44
[aliases]
55
test = pytest
6+
7+
[tool:pytest]
8+
# Only run benchmarks as tests.
9+
# To actually run the benchmarks, use --benchmark-enable on the command line.
10+
addopts = --benchmark-disable

‎tests/fixtures/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pytest import fixture # type: ignore
66

7-
__all__ = ["kitchen_sink_query", "kitchen_sink_sdl"]
7+
__all__ = ["kitchen_sink_query", "kitchen_sink_sdl", "big_schema_sdl"]
88

99

1010
def read_graphql(name):
@@ -20,3 +20,8 @@ def kitchen_sink_query():
2020
@fixture(scope="module")
2121
def kitchen_sink_sdl():
2222
return read_graphql("schema_kitchen_sink")
23+
24+
25+
@fixture(scope="module")
26+
def big_schema_sdl():
27+
return read_graphql("github_schema")

‎tests/fixtures/github_schema.graphql

Lines changed: 13158 additions & 0 deletions
Large diffs are not rendered by default.

‎tests/utilities/test_introspection_from_schema.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
from graphql import execute, build_schema, parse
12
from graphql.pyutils import dedent
23
from graphql.type import GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString
34
from graphql.utilities import (
45
build_client_schema,
56
print_schema,
67
introspection_from_schema,
8+
introspection_query,
79
)
810

11+
# noinspection PyUnresolvedReferences
12+
from ..fixtures import big_schema_sdl # noqa: F401
13+
914

1015
def introspection_to_sdl(introspection):
1116
return print_schema(build_client_schema(introspection))
@@ -56,3 +61,11 @@ def converts_a_simple_schema_without_description():
5661
}
5762
"""
5863
)
64+
65+
def benchmark_executing_introspection_query(
66+
benchmark, big_schema_sdl # noqa: F811
67+
):
68+
schema = build_schema(big_schema_sdl)
69+
query = parse(introspection_query.get_introspection_query())
70+
result = benchmark(lambda: execute(schema, query))
71+
assert result.errors is None

‎tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ deps =
4141
pytest-asyncio>=0.10
4242
pytest-cov>=2.7,<3
4343
pytest-describe>=0.12
44+
pytest-benchmark
4445
commands =
4546
pytest tests {posargs}

0 commit comments

Comments
 (0)
Please sign in to comment.