Skip to content

Commit 01d228a

Browse files
committed
Avoid warnings in latest pytest version
Shared functions in describe blocks that should not be treated as tests should start with an underscore (do not use the fixture decorator here).
1 parent 0bf55be commit 01d228a

File tree

8 files changed

+148
-167
lines changed

8 files changed

+148
-167
lines changed

tests/execution/test_nonnull.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from inspect import isawaitable
3-
from pytest import fixture, mark
3+
from pytest import mark
44

55
from graphql.execution import execute
66
from graphql.language import parse
@@ -533,8 +533,7 @@ async def throws():
533533
def describe_handles_non_null_argument():
534534

535535
# noinspection PyPep8Naming
536-
@fixture
537-
def resolve(_obj, _info, cannotBeNull):
536+
def _resolve(_obj, _info, cannotBeNull):
538537
if isinstance(cannotBeNull, str):
539538
return f"Passed: {cannotBeNull}"
540539

@@ -549,7 +548,7 @@ def resolve(_obj, _info, cannotBeNull):
549548
GraphQLNonNull(GraphQLString)
550549
)
551550
},
552-
resolve=resolve,
551+
resolve=_resolve,
553552
)
554553
},
555554
)

tests/execution/test_resolve.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from json import dumps
22

3-
from pytest import fixture
4-
53
from graphql import graphql_sync
64
from graphql.type import (
75
GraphQLArgument,
@@ -14,12 +12,11 @@
1412

1513

1614
def describe_execute_resolve_function():
17-
@fixture
18-
def test_schema(test_field):
15+
def _test_schema(test_field):
1916
return GraphQLSchema(GraphQLObjectType("Query", {"test": test_field}))
2017

2118
def default_function_accesses_attributes():
22-
schema = test_schema(GraphQLField(GraphQLString))
19+
schema = _test_schema(GraphQLField(GraphQLString))
2320

2421
class Source:
2522
test = "testValue"
@@ -30,14 +27,14 @@ class Source:
3027
)
3128

3229
def default_function_accesses_keys():
33-
schema = test_schema(GraphQLField(GraphQLString))
30+
schema = _test_schema(GraphQLField(GraphQLString))
3431

3532
source = {"test": "testValue"}
3633

3734
assert graphql_sync(schema, "{ test }", source) == ({"test": "testValue"}, None)
3835

3936
def default_function_calls_methods():
40-
schema = test_schema(GraphQLField(GraphQLString))
37+
schema = _test_schema(GraphQLField(GraphQLString))
4138

4239
class Source:
4340
_secret = "testValue"
@@ -51,7 +48,7 @@ def test(self, _info):
5148
)
5249

5350
def default_function_passes_args_and_context():
54-
schema = test_schema(
51+
schema = _test_schema(
5552
GraphQLField(GraphQLInt, args={"addend1": GraphQLArgument(GraphQLInt)})
5653
)
5754

@@ -73,7 +70,7 @@ class Context:
7370
)
7471

7572
def uses_provided_resolve_function():
76-
schema = test_schema(
73+
schema = _test_schema(
7774
GraphQLField(
7875
GraphQLString,
7976
args={

tests/execution/test_sync.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from inspect import isawaitable
22

3-
from pytest import fixture, mark, raises
3+
from pytest import mark, raises
44

55
from graphql import graphql_sync
66
from graphql.execution import execute
@@ -9,25 +9,23 @@
99

1010

1111
def describe_execute_synchronously_when_possible():
12-
@fixture
13-
def resolve_sync(root_value, info_):
12+
def _resolve_sync(root_value, info_):
1413
return root_value
1514

16-
@fixture
17-
async def resolve_async(root_value, info_):
15+
async def _resolve_async(root_value, info_):
1816
return root_value
1917

2018
schema = GraphQLSchema(
2119
GraphQLObjectType(
2220
"Query",
2321
{
24-
"syncField": GraphQLField(GraphQLString, resolve=resolve_sync),
25-
"asyncField": GraphQLField(GraphQLString, resolve=resolve_async),
22+
"syncField": GraphQLField(GraphQLString, resolve=_resolve_sync),
23+
"asyncField": GraphQLField(GraphQLString, resolve=_resolve_async),
2624
},
2725
),
2826
GraphQLObjectType(
2927
"Mutation",
30-
{"syncMutationField": GraphQLField(GraphQLString, resolve=resolve_sync)},
28+
{"syncMutationField": GraphQLField(GraphQLString, resolve=_resolve_sync)},
3129
),
3230
)
3331

tests/type/test_definition.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import cast, Dict
22

3-
from pytest import fixture, mark, raises
3+
from pytest import mark, raises
44

55
from graphql.error import INVALID
66
from graphql.type import (
@@ -514,8 +514,7 @@ def rejects_object_type_with_incorrectly_typed_interfaces_as_a_function():
514514

515515

516516
def describe_type_system_object_fields_must_have_valid_resolve_values():
517-
@fixture
518-
def schema_with_object_with_field_resolver(resolve_value):
517+
def _schema_with_object_with_field_resolver(resolve_value):
519518
BadResolverType = GraphQLObjectType(
520519
"BadResolver",
521520
{"bad_field": GraphQLField(GraphQLString, resolve=resolve_value)},
@@ -525,17 +524,17 @@ def schema_with_object_with_field_resolver(resolve_value):
525524
)
526525

527526
def accepts_a_lambda_as_an_object_field_resolver():
528-
schema_with_object_with_field_resolver(lambda _obj, _info: {})
527+
_schema_with_object_with_field_resolver(lambda _obj, _info: {})
529528

530529
def rejects_an_empty_object_field_resolver():
531530
with raises(TypeError) as exc_info:
532-
schema_with_object_with_field_resolver({})
531+
_schema_with_object_with_field_resolver({})
533532
msg = str(exc_info.value)
534533
assert msg == "Field resolver must be a function if provided, but got: {}."
535534

536535
def rejects_a_constant_scalar_value_resolver():
537536
with raises(TypeError) as exc_info:
538-
schema_with_object_with_field_resolver(0)
537+
_schema_with_object_with_field_resolver(0)
539538
msg = str(exc_info.value)
540539
assert msg == "Field resolver must be a function if provided, but got: 0."
541540

tests/type/test_validation.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import cast
22

3-
from pytest import fixture, mark, raises
3+
from pytest import mark, raises
44

55
from graphql.language import parse
66
from graphql.type import (
@@ -784,8 +784,7 @@ def schema_with_enum(name):
784784

785785

786786
def describe_type_system_object_fields_must_have_output_types():
787-
@fixture
788-
def schema_with_object_field_of_type(field_type):
787+
def _schema_with_object_field_of_type(field_type):
789788
BadObjectType = GraphQLObjectType(
790789
"BadObject", {"badField": GraphQLField(field_type)}
791790
)
@@ -796,29 +795,29 @@ def schema_with_object_field_of_type(field_type):
796795

797796
@mark.parametrize("type_", output_types)
798797
def accepts_an_output_type_as_an_object_field_type(type_):
799-
schema = schema_with_object_field_of_type(type_)
798+
schema = _schema_with_object_field_of_type(type_)
800799
assert validate_schema(schema) == []
801800

802801
def rejects_an_empty_object_field_type():
803802
# invalid schema cannot be built with Python
804803
with raises(TypeError) as exc_info:
805-
schema_with_object_field_of_type(None)
804+
_schema_with_object_field_of_type(None)
806805
msg = str(exc_info.value)
807806
assert msg == "Field type must be an output type."
808807

809808
@mark.parametrize("type_", not_output_types)
810809
def rejects_a_non_output_type_as_an_object_field_type(type_):
811810
# invalid schema cannot be built with Python
812811
with raises(TypeError) as exc_info:
813-
schema_with_object_field_of_type(type_)
812+
_schema_with_object_field_of_type(type_)
814813
msg = str(exc_info.value)
815814
assert msg == "Field type must be an output type."
816815

817816
@mark.parametrize("type_", [int, float, str])
818817
def rejects_a_non_type_value_as_an_object_field_type(type_):
819818
# invalid schema cannot be built with Python
820819
with raises(TypeError) as exc_info:
821-
schema_with_object_field_of_type(type_)
820+
_schema_with_object_field_of_type(type_)
822821
msg = str(exc_info.value)
823822
assert msg == "Field type must be an output type."
824823

@@ -1064,8 +1063,7 @@ def rejects_object_implementing_extended_interface_due_to_type_mismatch():
10641063

10651064

10661065
def describe_type_system_interface_fields_must_have_output_types():
1067-
@fixture
1068-
def schema_with_interface_field_of_type(field_type):
1066+
def _schema_with_interface_field_of_type(field_type):
10691067
BadInterfaceType = GraphQLInterfaceType(
10701068
"BadInterface", {"badField": GraphQLField(field_type)}
10711069
)
@@ -1081,29 +1079,29 @@ def schema_with_interface_field_of_type(field_type):
10811079

10821080
@mark.parametrize("type_", output_types)
10831081
def accepts_an_output_type_as_an_interface_field_type(type_):
1084-
schema = schema_with_interface_field_of_type(type_)
1082+
schema = _schema_with_interface_field_of_type(type_)
10851083
assert validate_schema(schema) == []
10861084

10871085
def rejects_an_empty_interface_field_type():
10881086
# invalid schema cannot be built with Python
10891087
with raises(TypeError) as exc_info:
1090-
schema_with_interface_field_of_type(None)
1088+
_schema_with_interface_field_of_type(None)
10911089
msg = str(exc_info.value)
10921090
assert msg == "Field type must be an output type."
10931091

10941092
@mark.parametrize("type_", not_output_types)
10951093
def rejects_a_non_output_type_as_an_interface_field_type(type_):
10961094
# invalid schema cannot be built with Python
10971095
with raises(TypeError) as exc_info:
1098-
schema_with_interface_field_of_type(type_)
1096+
_schema_with_interface_field_of_type(type_)
10991097
msg = str(exc_info.value)
11001098
assert msg == "Field type must be an output type."
11011099

11021100
@mark.parametrize("type_", [int, float, str])
11031101
def rejects_a_non_type_value_as_an_interface_field_type(type_):
11041102
# invalid schema cannot be built with Python
11051103
with raises(TypeError) as exc_info:
1106-
schema_with_interface_field_of_type(type_)
1104+
_schema_with_interface_field_of_type(type_)
11071105
msg = str(exc_info.value)
11081106
assert msg == "Field type must be an output type."
11091107

@@ -1151,8 +1149,7 @@ def accepts_an_interface_not_implemented_by_at_least_one_object():
11511149

11521150

11531151
def describe_type_system_field_arguments_must_have_input_types():
1154-
@fixture
1155-
def schema_with_arg_of_type(arg_type):
1152+
def _schema_with_arg_of_type(arg_type):
11561153
BadObjectType = GraphQLObjectType(
11571154
"BadObject",
11581155
{
@@ -1167,29 +1164,29 @@ def schema_with_arg_of_type(arg_type):
11671164

11681165
@mark.parametrize("type_", input_types)
11691166
def accepts_an_input_type_as_a_field_arg_type(type_):
1170-
schema = schema_with_arg_of_type(type_)
1167+
schema = _schema_with_arg_of_type(type_)
11711168
assert validate_schema(schema) == []
11721169

11731170
def rejects_an_empty_field_arg_type():
11741171
# invalid schema cannot be built with Python
11751172
with raises(TypeError) as exc_info:
1176-
schema_with_arg_of_type(None)
1173+
_schema_with_arg_of_type(None)
11771174
msg = str(exc_info.value)
11781175
assert msg == "Argument type must be a GraphQL input type."
11791176

11801177
@mark.parametrize("type_", not_input_types)
11811178
def rejects_a_non_input_type_as_a_field_arg_type(type_):
11821179
# invalid schema cannot be built with Python
11831180
with raises(TypeError) as exc_info:
1184-
schema_with_arg_of_type(type_)
1181+
_schema_with_arg_of_type(type_)
11851182
msg = str(exc_info.value)
11861183
assert msg == "Argument type must be a GraphQL input type."
11871184

11881185
@mark.parametrize("type_", [int, float, str])
11891186
def rejects_a_non_type_value_as_a_field_arg_type(type_):
11901187
# invalid schema cannot be built with Python
11911188
with raises(TypeError) as exc_info:
1192-
schema_with_arg_of_type(type_)
1189+
_schema_with_arg_of_type(type_)
11931190
msg = str(exc_info.value)
11941191
assert msg == "Argument type must be a GraphQL input type."
11951192

@@ -1215,8 +1212,7 @@ def rejects_a_non_input_type_as_a_field_arg_with_locations():
12151212

12161213

12171214
def describe_type_system_input_object_fields_must_have_input_types():
1218-
@fixture
1219-
def schema_with_input_field_of_type(input_field_type):
1215+
def _schema_with_input_field_of_type(input_field_type):
12201216
BadInputObjectType = GraphQLInputObjectType(
12211217
"BadInputObject", {"badField": GraphQLInputField(input_field_type)}
12221218
)
@@ -1234,29 +1230,29 @@ def schema_with_input_field_of_type(input_field_type):
12341230

12351231
@mark.parametrize("type_", input_types)
12361232
def accepts_an_input_type_as_an_input_fieldtype(type_):
1237-
schema = schema_with_input_field_of_type(type_)
1233+
schema = _schema_with_input_field_of_type(type_)
12381234
assert validate_schema(schema) == []
12391235

12401236
def rejects_an_empty_input_field_type():
12411237
# invalid schema cannot be built with Python
12421238
with raises(TypeError) as exc_info:
1243-
schema_with_input_field_of_type(None)
1239+
_schema_with_input_field_of_type(None)
12441240
msg = str(exc_info.value)
12451241
assert msg == "Input field type must be a GraphQL input type."
12461242

12471243
@mark.parametrize("type_", not_input_types)
12481244
def rejects_a_non_input_type_as_an_input_field_type(type_):
12491245
# invalid schema cannot be built with Python
12501246
with raises(TypeError) as exc_info:
1251-
schema_with_input_field_of_type(type_)
1247+
_schema_with_input_field_of_type(type_)
12521248
msg = str(exc_info.value)
12531249
assert msg == "Input field type must be a GraphQL input type."
12541250

12551251
@mark.parametrize("type_", [int, float, str])
12561252
def rejects_a_non_type_value_as_an_input_field_type(type_):
12571253
# invalid schema cannot be built with Python
12581254
with raises(TypeError) as exc_info:
1259-
schema_with_input_field_of_type(type_)
1255+
_schema_with_input_field_of_type(type_)
12601256
msg = str(exc_info.value)
12611257
assert msg == "Input field type must be a GraphQL input type."
12621258

0 commit comments

Comments
 (0)