Skip to content

Commit 753c69a

Browse files
authored
test: Make the tests pass in pytest-asyncio>=0.17 (#525)
Fixes #518 Unpin pytest-asyncio version. Adjust the event_loop fixture to make it compatible with pytest-asyncio>=0.17 Use the @pytest_asyncio.fixture decorator for apropriately.
1 parent 49e9fa7 commit 753c69a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

packages/google-cloud-firestore/noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def default(session):
108108
"asyncmock",
109109
"pytest",
110110
"pytest-cov",
111-
"pytest-asyncio<0.17.0",
111+
"pytest-asyncio",
112112
"-c",
113113
constraints_path,
114114
)
@@ -214,7 +214,7 @@ def system(session):
214214
"mock",
215215
"pytest",
216216
"google-cloud-testutils",
217-
"pytest-asyncio<0.17.0",
217+
"pytest-asyncio",
218218
"-c",
219219
constraints_path,
220220
)

packages/google-cloud-firestore/tests/system/test_system_async.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import itertools
1818
import math
1919
import pytest
20+
import pytest_asyncio
2021
import operator
2122
from typing import Callable, Dict, List, Optional
2223

@@ -40,7 +41,6 @@
4041
FIRESTORE_EMULATOR,
4142
)
4243

43-
_test_event_loop = asyncio.new_event_loop()
4444
pytestmark = pytest.mark.asyncio
4545

4646

@@ -62,7 +62,7 @@ def client():
6262
yield firestore.AsyncClient(project=project, credentials=credentials)
6363

6464

65-
@pytest.fixture
65+
@pytest_asyncio.fixture
6666
async def cleanup():
6767
operations = []
6868
yield operations.append
@@ -71,10 +71,13 @@ async def cleanup():
7171
await operation()
7272

7373

74-
@pytest.fixture
74+
@pytest.fixture(scope="module")
7575
def event_loop():
76-
asyncio.set_event_loop(_test_event_loop)
77-
return asyncio.get_event_loop()
76+
"""Change event_loop fixture to module level."""
77+
policy = asyncio.get_event_loop_policy()
78+
loop = policy.new_event_loop()
79+
yield loop
80+
loop.close()
7881

7982

8083
async def test_collections(client):
@@ -546,7 +549,7 @@ async def test_collection_add(client, cleanup):
546549
assert set([i async for i in collection3.list_documents()]) == {document_ref5}
547550

548551

549-
@pytest.fixture
552+
@pytest_asyncio.fixture
550553
async def query_docs(client):
551554
collection_id = "qs" + UNIQUE_RESOURCE_ID
552555
sub_collection = "child" + UNIQUE_RESOURCE_ID

0 commit comments

Comments
 (0)