Skip to content

Commit 073f086

Browse files
committed
Use AnyIO instead of pytest-asyncio for running async tests
1 parent fa8f9b5 commit 073f086

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" }
@@ -321,7 +322,7 @@ addopts = "--benchmark-disable"
321322
# Deactivate default name pattern for test classes (we use pytest_describe).
322323
python_classes = "PyTest*"
323324
# Handle all async fixtures and tests automatically by asyncio,
324-
asyncio_mode = "auto"
325+
asyncio_mode = "strict"
325326
# Set a timeout in seconds for aborting tests that run too long.
326327
timeout = "100"
327328
# 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)