quart icon indicating copy to clipboard operation
quart copied to clipboard

fix async_generator error by making the app fixture async

Open john0isaac opened this issue 1 year ago • 4 comments

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'
  • fixes #335

Checklist:

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

john0isaac avatar Apr 26 '24 21:04 john0isaac

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

pgjones avatar May 19 '24 19:05 pgjones

@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 avatar May 19 '24 20:05 john0isaac

@pgjones I did look further at your example, you are not following the documentation on how to configure a test.

To configure your test you are using the app from backend.run which is an instance of Quart()

image

https://github.com/pgjones/tozo/blob/main/backend/src/backend/run.py#L22 image

The documentation clearly instructs to use the create_app() method which I'm using in my configuration https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/blob/main/tests/conftest.py And when you use create_app it doesn't work the same way as if you are using an instance of a class as it's a function.

So, There are two solutions:

  • My approach using the create_app method.
  • Your approach using app which is an instance of Quart

john0isaac avatar May 31 '24 17:05 john0isaac