Skip to content

fix(python-aiohttp): use async client fixture for pytest-aiohttp 1.x (fixes Python Server CI) - #25372

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
khayashi4337:fix/python-aiohttp-pytest-loop-fixture
Oct 23, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
khayashi4337:fix/python-aiohttp-pytest-loop-fixture

Conversation

@khayashi4337

@khayashi4337 khayashi4337 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The Python Server workflow (.github/workflows/samples-python-server.yaml) fails on master and on the v7.26.0 / v7.25.0 release runs. It also fails on PRs that touch the python-aiohttp samples, for example #25362. Every generated test errors at setup with:

E       fixture 'loop' not found

The cause is the generated tests/conftest.py: its client fixture takes loop and calls loop.run_until_complete(aiohttp_client(app.app)), while test-requirements.txt asks for pytest-aiohttp>=0.3.0 with no upper bound. pytest-aiohttp 1.0 moved to pytest-asyncio, made aiohttp_client an async fixture and deprecated loop, and 1.1.0 removed loop (see its CHANGES and README).

Changes (python-aiohttp)

  • conftest.mustache: client becomes an async fixture that does return await aiohttp_client(app.app), as pytest-aiohttp's README recommends.
  • tox.mustache: add [pytest] asyncio_mode = auto (non-nose branch), so the async fixture and tests run under pytest-asyncio's default strict mode. Plain pytest also reads tox.ini; the generated project has no competing pytest.ini / setup.cfg / pyproject.toml.
  • test-requirements.mustache: pytest-aiohttp>=1.0.0 and pytest-asyncio>=0.17.2. pytest~=7.1.0 is unchanged. pip resolves this to a compatible set, for example pytest 7.1.3, pytest-asyncio 0.23.8 and pytest-aiohttp 1.1.0.
  • Regenerated samples/server/petstore/python-aiohttp-srclayout (tests/conftest.py, tox.ini, test-requirements.txt).

I chose this over pinning pytest-aiohttp<1, which would keep relying on an API that pytest-aiohttp has removed.

Verification

With Python 3.9.25 (the version the workflow uses), running make test-all in samples/server/petstore/python-aiohttp-srclayout in a fresh copy:

  • before: 9 skipped, 11 errors (all fixture 'loop' not found), with pytest-aiohttp 1.1.0, pytest 7.1.3 and pytest-asyncio 0.23.8
  • after: 11 passed, 9 skipped, py3: OK

Only that environment was exercised, not every version combination the requirements allow. Python*Test / AbstractPython*Test pass; no Java code changed. With useNose enabled, dependencies and the test command are unchanged, but the conftest change applies to both modes, as before.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Regenerated the samples for bin/configs/python-aiohttp*.yaml (the only affected generator) and committed the three changed files. Generator options and docs are unchanged.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc @cbornet @tomplus @krjakbrjak @fa0311 (Python technical committee)

Parts of this change were drafted with AI coding assistants (Devin, Claude Code) and reviewed and verified by me.

🤖 Generated with Claude Code


Summary by cubic

Fixes the Python Server CI, which failed on master and the v7.25.0/v7.26.0 release runs because generated python-aiohttp tests rely on the loop fixture that pytest-aiohttp 1.1.0 removed.

  • Defines the client fixture as async and awaits aiohttp_client(app.app) instead of loop.run_until_complete.
  • Adds asyncio_mode = auto to the generated tox.ini so async fixtures run under pytest-asyncio.
  • Requires pytest-aiohttp>=1.0.0 and pytest-asyncio>=0.17.2 in generated test requirements.
  • Regenerates the python-aiohttp-srclayout sample.

With Python 3.9.25, the sample's tests go from 9 skipped, 11 errors to 11 passed, 9 skipped.

Written for commit 0022c0d. Summary will update on new commits.

View guided diff

… 1.x

pytest-aiohttp 1.x switched to pytest-asyncio and removed the deprecated
`loop` fixture in 1.1.0, causing `fixture 'loop' not found` errors in
generated tests.

Update `conftest.mustache` to define `client` as an async fixture awaiting
`aiohttp_client(app.app)`, configure `asyncio_mode = auto` in `tox.mustache`,
and require `pytest-aiohttp>=1.0.0` and `pytest-asyncio>=0.17.2` in
`test-requirements.mustache`.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 6 files

View guided diff | Re-trigger cubic

@wing328 wing328 added this to the 7.27.0 milestone Oct 23, 2026
@wing328
wing328 merged commit 5e13f51 into OpenAPITools:master Oct 23, 2026
16 checks passed
@wing328

wing328 commented Oct 23, 2026

Copy link
Copy Markdown
Member

thanks for the fix, which has been merged.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants