Skip to content

test(gapic-generator): Update gapic generator to resolve pytest-asyncio errors.#17260

Merged
chalmerlowe merged 10 commits into
mainfrom
feat/universal-generator-fixes-asyncio-test
May 27, 2026
Merged

test(gapic-generator): Update gapic generator to resolve pytest-asyncio errors.#17260
chalmerlowe merged 10 commits into
mainfrom
feat/universal-generator-fixes-asyncio-test

Conversation

@chalmerlowe
Copy link
Copy Markdown
Contributor

@chalmerlowe chalmerlowe commented May 26, 2026

This PR updates the Python GAPIC generator templates to support modern EOL Python support drops natively across the entire SDK.

Changes

  • setup.py.j2: Bumps the baseline minimum grpcio dependency requirement to >= 1.59.0. This robust minimum requirement resolves the pytest-asyncio event loop regressions universally, removing the need for custom pytest-asyncio overrides.
  • noxfile.py.j2: Replaced the hardcoded constraints path with a dynamic constraints file path resolver at runtime, ensuring that monorepos natively resolve to their version-specific constraints files (e.g., testing/constraints-3.10.txt).
  • pytest-asyncio Updates the gapic-generator in order to resolve an issue with pytest-asyncio failures across Python runtimes 3.10 - 3.14.

Copy link
Copy Markdown
Contributor

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

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 updates dependencies (such as bumping grpcio and adding pytest-asyncio), adjusts constraints file resolution logic in noxfile.py.j2, and introduces an autouse fixture to manage the asyncio event loop in generated unit tests. Feedback from the reviewer highlights three main areas of improvement: first, the specified version of pytest-asyncio>=1.3.0 does not exist on PyPI and will cause installation failures; second, the use of asyncio.get_event_loop() is deprecated and can leak resources, which can be resolved by using the event loop policy and cleanly closing newly created loops; and third, the constraints file resolution logic in noxfile.py.j2 can be simplified and made more robust by directly checking for the file's existence.

Comment thread packages/gapic-generator/gapic/templates/testing/constraints-3.14.txt.j2 Outdated
Comment thread packages/gapic-generator/gapic/templates/noxfile.py.j2
Comment thread packages/gapic-generator/tests/integration/goldens/asset/noxfile.py
@chalmerlowe chalmerlowe marked this pull request as ready for review May 26, 2026 19:50
@chalmerlowe chalmerlowe requested a review from a team as a code owner May 26, 2026 19:50
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented May 26, 2026

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@chalmerlowe chalmerlowe changed the title test(gapic-generator): [EXPERIMENTAL] pin pytest-asyncio and freeze logs test(gapic-generator): [EXPERIMENTAL FOR DISCUSSION] pin pytest-asyncio and freeze logs May 26, 2026
@chalmerlowe chalmerlowe changed the title test(gapic-generator): [EXPERIMENTAL FOR DISCUSSION] pin pytest-asyncio and freeze logs test(gapic-generator): Update gapic generator to resolve pytest-asyncio errors. May 27, 2026
@pytest.fixture(autouse=True)
def set_event_loop():
try:
asyncio.get_event_loop_policy().get_event_loop()
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.

There's a deprecation warning in the logs:

test_messaging.py:121: DeprecationWarning: 'asyncio.get_event_loop_policy' is deprecated and slated for removal in Python 3.16

Is there a different method we should use as the default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great question.

We have an alternate solution. Gonna regen the goldens and update this snippet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved.
get_running_loop() is the modern, standard API that avoids deprecation warnings on Python 3.10+ and remains supported in future Python 3.16+ runtimes!

@chalmerlowe chalmerlowe added this to the generate via 1.32.0 milestone May 27, 2026
…plate to prevent Python 3.16 deprecation warnings
Copy link
Copy Markdown
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

LGTM

@chalmerlowe chalmerlowe merged commit 204b6d0 into main May 27, 2026
92 checks passed
@chalmerlowe chalmerlowe deleted the feat/universal-generator-fixes-asyncio-test branch May 27, 2026 01:22
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.

3 participants