Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix async_generator error by making the app fixture async#336

Open
john0isaac wants to merge 8 commits into
pallets:main from
john0isaac:patch-1
Open

fix async_generator error by making the app fixture async #336
john0isaac wants to merge 8 commits into
pallets:main from
john0isaac:patch-1

Conversation

@john0isaac

@john0isaac john0isaac commented Apr 26, 2024
edited
Loading

Copy link
Copy Markdown

The app fixture is not created as an async fixture which results in breaking the second part of the documentation where we attempt to access the test_client() it gives an async_generator.
This PR fixes that to pass the tests

AttributeError: 'async_generator' object has no attribute 'test_client'

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

We are yielding the app fixture but not passing it as an argument which seems to break the second part of the documentation where we attempt to access the `test_client()` it gives an async_generator.
```bash
AttributeError: 'async_generator' object has no attribute 'test_client'
```
@john0isaac john0isaac changed the title (削除) fix async_generator error by passing the fixture name as an argument (削除ここまで) (追記) fix async_generator error by making the app fixture async (追記ここまで) Apr 27, 2024

pgjones commented May 19, 2024

Copy link
Copy Markdown
Member

Does this depend on the pytest-asyncio mode you are using? As it works for me without this change here

john0isaac commented May 19, 2024
edited
Loading

Copy link
Copy Markdown
Author

@pgjones I'm using the default values for everything.

I will reproduce and get back to you with the detailed versions of everything in an isolated environment.

This is my working setup here.

Have you tested this recently? Maybe it changed in the latest versions but was working previously..

My change works on Python 3.10, 3.11, 3.12

but I will reproduce again and leave detailed comment with it.

john0isaac commented May 31, 2024
edited
Loading

Copy link
Copy Markdown
Author

@pgjones I looked further into your setup and found the reason it works for you. Your project has asyncio_mode = "auto" configured in pyproject.toml:

[tool.pytest.ini_options]
asyncio_mode = "auto"

With asyncio_mode = "auto", pytest-asyncio automatically converts coroutines and async generator functions declared with @pytest.fixture to pytest-asyncio fixtures. Without it, the default mode is strict, which only evaluates async fixtures decorated with @pytest_asyncio.fixture so @pytest.fixture on an async def function does not await the coroutine and returns the raw async_generator object instead, causing:

AttributeError: 'async_generator' object has no attribute 'test_client'

So there are actually two valid fixes for users hitting this error:

  1. Use @pytest_asyncio.fixture instead of @pytest.fixture (this PR)
  2. Add asyncio_mode = "auto" to [tool.pytest.ini_options] in your pytest config

Since the Quart docs don't mention the asyncio_mode setting, most users following them will hit this error. This PR addresses that by making the decorator explicit.

urucoder commented Jan 8, 2025

Copy link
Copy Markdown

I can confirm that I faced the same issue following the documentation and this simple fix solved it

john0isaac reacted with thumbs up emoji

john0isaac commented Jun 2, 2026
edited
Loading

Copy link
Copy Markdown
Author

@pgjones sorry I missed something when I left the last comment and I went back to try to understand this more I now know that my original comment didn't make sense so sorry for that

I edited my comment with the correct explanation of the issue and why it is working for you in your sample and not working here I missed checking your pytest setup in pyproject.toml

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Docs] AttributeError: 'async_generator' object has no attribute 'test_client'

AltStyle によって変換されたページ (->オリジナル) /