Skip to content

test: ignore pytest-asyncio loop scope deprecation warning under pytest 9.2 - #18879

Open
chalmerlowe wants to merge 1 commit into
mainfrom
test/ignore-pytest-asyncio-loop-scope-warning
Open

chalmerlowe wants to merge 1 commit into
mainfrom
test/ignore-pytest-asyncio-loop-scope-warning

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Context

In pytest 9.2.0, three upstream changes break CI across packages in this repository:

  1. Config._do_configure() applies configured warning filters (filterwarnings from pytest.ini or pyproject.toml) inside self._catch_configured_warnings() before invoking self.hook.pytest_configure.call_historic(...). When pytest-asyncio is installed in the test environment (either directly by a package or via the shared NOX_ENVDIR virtual environment in CI), its pytest_configure hook emits:

    pytest.PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
    

    Under filterwarnings = error, pytest 9.2.0 promotes this pytest_configure hook warning into an immediate INTERNALERROR startup failure (exit code 3).

  2. pytest 9.2.0 emits pytest.PytestRemovedIn10Warning: Module-scoped fixtures defined as instance methods are deprecated (a subclass of PytestDeprecationWarning), which causes packages/google-auth-httplib2 tests (RequestResponseTests.server in tests/compliance.py) to fail under filterwarnings = error.

  3. pytest 9.2.0 renamed FixtureManager._arg2fixturedefs to _arg2node2fixturedefs. Because packages/google-cloud-firestore/noxfile.py pinned pytest-asyncio==0.21.2, test collection in packages/google-cloud-firestore fails with AttributeError: 'FixtureManager' object has no attribute '_arg2fixturedefs'.

Solution

  • Add ignore:.*asyncio_default_fixture_loop_scope.*:pytest.PytestDeprecationWarning to filterwarnings across all 13 packages in the repository that set filterwarnings = error.
  • Add ignore:.*Module-scoped fixtures defined as instance methods are deprecated.*:pytest.PytestDeprecationWarning to packages/google-auth-httplib2/pytest.ini.
  • Unpin pytest-asyncio==0.21.2 in packages/google-cloud-firestore/noxfile.py (and remove the corresponding post-processing rule in .librarian/generator-input/client-post-processing/firestore-integration.yaml):
    • Ensure an active event loop is present for TestAsyncBundle.test_async_query (packages/google-cloud-firestore/tests/unit/v1/test_bundle.py) and test_baseclient__emulator_channel (packages/google-cloud-firestore/tests/unit/v1/test_base_client.py) since pytest-asyncio >= 0.23.0 clears the thread event loop on teardown.
    • Replace the removed def event_loop(): fixture override in packages/google-cloud-firestore/tests/system/test_system_async.py and packages/google-cloud-firestore/tests/system/test_pipeline_acceptance.py with loop_scope="module" so module-scoped AsyncClient fixtures share a module-scoped event loop under pytest-asyncio >= 1.0.

Notes for Reviewers

Using a filterwarnings ignore rule rather than setting asyncio_default_fixture_loop_scope = function in pytest.ini preserves compatibility with test sessions where pytest-asyncio is not installed (such as google-api-core sessions with install_async_rest=False) or where older versions of pytest-asyncio are used, avoiding PytestConfigWarning: Unknown config option: asyncio_default_fixture_loop_scope under filterwarnings = error.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a pytest warning filter across multiple packages to ignore deprecation warnings about the unset "asyncio_default_fixture_loop_scope" configuration option. The reviewer recommends using a wildcard pattern (".asyncio_default_fixture_loop_scope.") instead of the exact warning string. This improvement makes the filters more robust against future upstream wording changes and simplifies the TOML configuration by eliminating the need to escape double quotes.

Comment thread packages/db-dtypes/pytest.ini Outdated
Comment thread packages/google-api-core/pyproject.toml Outdated
Comment thread packages/google-auth-httplib2/pytest.ini Outdated
Comment thread packages/google-cloud-core/pytest.ini Outdated
Comment thread packages/google-cloud-dns/pytest.ini Outdated
Comment thread packages/google-cloud-logging/pytest.ini Outdated
Comment thread packages/google-cloud-pubsub/pytest.ini Outdated
Comment thread packages/google-cloud-runtimeconfig/pytest.ini Outdated
Comment thread packages/google-cloud-testutils/pytest.ini Outdated
Comment thread packages/proto-plus/pytest.ini Outdated
@chalmerlowe
chalmerlowe force-pushed the test/ignore-pytest-asyncio-loop-scope-warning branch 4 times, most recently from 118db24 to 9129eed Compare October 28, 2026 01:47
@chalmerlowe
chalmerlowe force-pushed the test/ignore-pytest-asyncio-loop-scope-warning branch from 9129eed to d93d529 Compare October 28, 2026 08:39
@chalmerlowe
chalmerlowe marked this pull request as ready for review October 28, 2026 10:59
@chalmerlowe
chalmerlowe requested review from a team as code owners October 28, 2026 10:59
@chalmerlowe
chalmerlowe requested review from sindhuvy and removed request for a team October 28, 2026 10:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant