Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4ea6d04

Browse files
Use AnyIO instead of pytest-asyncio for running async tests (#242)
1 parent 54fe279 commit 4ea6d04

25 files changed

+139
-221
lines changed

‎poetry.lock‎

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

‎pyproject.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typing-extensions = [
5252
optional = true
5353

5454
[tool.poetry.group.test.dependencies]
55+
anyio = { version = ">= 3.7.1" }
5556
pytest = [
5657
{ version = "^8.3", python = ">=3.8" },
5758
{ version = "^7.4", python = "<3.8" }
@@ -322,7 +323,7 @@ addopts = "--benchmark-disable"
322323
# Deactivate default name pattern for test classes (we use pytest_describe).
323324
python_classes = "PyTest*"
324325
# Handle all async fixtures and tests automatically by asyncio,
325-
asyncio_mode = "auto"
326+
asyncio_mode = "strict"
326327
# Set a timeout in seconds for aborting tests that run too long.
327328
timeout = "100"
328329
# Ignore config options not (yet) available in older Python versions.

‎tests/conftest.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ def pytest_collection_modifyitems(config, items):
2020
for item in items:
2121
if "slow" in item.keywords:
2222
item.add_marker(skip_slow)
23+
24+
25+
@pytest.fixture
26+
def anyio_backend():
27+
return "asyncio"

‎tests/execution/test_abstract.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
def sync_and_async(spec):
2424
"""Decorator for running a test synchronously and asynchronously."""
25-
return pytest.mark.asyncio(
25+
return pytest.mark.anyio(
2626
pytest.mark.parametrize("sync", [True, False], ids=("sync", "async"))(spec)
2727
)
2828

2929

3030
def access_variants(spec):
3131
"""Decorator for tests with dict and object access, including inheritance."""
32-
return pytest.mark.asyncio(
32+
return pytest.mark.anyio(
3333
pytest.mark.parametrize("access", ["dict", "object", "inheritance"])(spec)
3434
)
3535

‎tests/execution/test_customize.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from graphql.language import parse
77
from graphql.type import GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString
88

9+
pytestmark = pytest.mark.anyio
10+
911
try:
1012
anext # noqa: B018
1113
except NameError: # pragma: no cover (Python < 3.10)
@@ -78,7 +80,6 @@ def execute_field(
7880

7981

8082
def describe_customize_subscription():
81-
@pytest.mark.asyncio
8283
async def uses_a_custom_subscribe_field_resolver():
8384
schema = GraphQLSchema(
8485
query=GraphQLObjectType("Query", {"foo": GraphQLField(GraphQLString)}),
@@ -107,7 +108,6 @@ async def custom_foo():
107108

108109
await subscription.aclose()
109110

110-
@pytest.mark.asyncio
111111
async def uses_a_custom_execution_context_class():
112112
class TestExecutionContext(ExecutionContext):
113113
def __init__(self, *args, **kwargs):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /