Skip to content

Commit

Permalink
fix: Async system tests were not unwrapping async_generators (#1086)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
clundin25 committed Jul 22, 2022
1 parent 6f49d1f commit 29d248a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
15 changes: 8 additions & 7 deletions system_tests/system_tests_async/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import google.auth.transport.requests
import google.auth.transport.urllib3
import pytest
import pytest_asyncio
import requests
import urllib3

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


@pytest.fixture
@pytest_asyncio.fixture
def service_account_file():
"""The full path to a valid service account key file."""
yield sync_conftest.SERVICE_ACCOUNT_FILE


@pytest.fixture
@pytest_asyncio.fixture
def impersonated_service_account_file():
"""The full path to a valid service account key file."""
yield sync_conftest.IMPERSONATED_SERVICE_ACCOUNT_FILE


@pytest.fixture
@pytest_asyncio.fixture
def authorized_user_file():
"""The full path to a valid authorized user file."""
yield sync_conftest.AUTHORIZED_USER_FILE


@pytest.fixture
@pytest_asyncio.fixture
async def aiohttp_session():
async with aiohttp.ClientSession(auto_decompress=False) as session:
yield session


@pytest.fixture(params=["aiohttp"])
@pytest_asyncio.fixture(params=["aiohttp"])
async def http_request(request, aiohttp_session):
"""A transport.request object."""
yield aiohttp_requests.Request(aiohttp_session)


@pytest.fixture
@pytest_asyncio.fixture
async def token_info(http_request):
"""Returns a function that obtains OAuth2 token info."""

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


@pytest.fixture
@pytest_asyncio.fixture
async def verify_refresh(http_request):
"""Returns a function that verifies that credentials can be refreshed."""

Expand Down

0 comments on commit 29d248a

Please sign in to comment.