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

Merged
KH
1d ago
+16-6

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.