Skip to content

Commit fcec601

Browse files
authored
fix: Async system tests were not unwrapping async_generators (#1086)
Currently the system tests were failing with a message "TypeError: 'async_generator' object is not callable". This is because newer versions of pytest_asyncio uses "strict" mode by default which does not automatically convert fixtures to async fixtures in async test cases. This became an issue as of pytest_asyncio version 19. The solution is to either switch the mode to "auto" in the nox commandline or to mark the async fixtures as async fixtures. I've opted for the second to avoid making this hard to discover.
1 parent 41dff98 commit fcec601

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
0 Bytes
Binary file not shown.

packages/google-auth/system_tests/system_tests_async/conftest.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import google.auth.transport.requests
2020
import google.auth.transport.urllib3
2121
import pytest
22+
import pytest_asyncio
2223
import requests
2324
import urllib3
2425

@@ -30,37 +31,37 @@
3031
TOKEN_INFO_URL = "https://www.googleapis.com/oauth2/v3/tokeninfo"
3132

3233

33-
@pytest.fixture
34+
@pytest_asyncio.fixture
3435
def service_account_file():
3536
"""The full path to a valid service account key file."""
3637
yield sync_conftest.SERVICE_ACCOUNT_FILE
3738

3839

39-
@pytest.fixture
40+
@pytest_asyncio.fixture
4041
def impersonated_service_account_file():
4142
"""The full path to a valid service account key file."""
4243
yield sync_conftest.IMPERSONATED_SERVICE_ACCOUNT_FILE
4344

4445

45-
@pytest.fixture
46+
@pytest_asyncio.fixture
4647
def authorized_user_file():
4748
"""The full path to a valid authorized user file."""
4849
yield sync_conftest.AUTHORIZED_USER_FILE
4950

5051

51-
@pytest.fixture
52+
@pytest_asyncio.fixture
5253
async def aiohttp_session():
5354
async with aiohttp.ClientSession(auto_decompress=False) as session:
5455
yield session
5556

5657

57-
@pytest.fixture(params=["aiohttp"])
58+
@pytest_asyncio.fixture(params=["aiohttp"])
5859
async def http_request(request, aiohttp_session):
5960
"""A transport.request object."""
6061
yield aiohttp_requests.Request(aiohttp_session)
6162

6263

63-
@pytest.fixture
64+
@pytest_asyncio.fixture
6465
async def token_info(http_request):
6566
"""Returns a function that obtains OAuth2 token info."""
6667

@@ -85,7 +86,7 @@ async def _token_info(access_token=None, id_token=None):
8586
yield _token_info
8687

8788

88-
@pytest.fixture
89+
@pytest_asyncio.fixture
8990
async def verify_refresh(http_request):
9091
"""Returns a function that verifies that credentials can be refreshed."""
9192

0 commit comments

Comments
 (0)