-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add async test client #2937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add async test client #2937
Conversation
Nice! 😁 |
Should all tests also be run with the |
Any idea about the best way to factorize code between |
No, that would be too huge of a PR (but also, I don't think we should do it). You just need to test the client itself. |
If we can parameterize tests so that they use both
The thing is that we don't get enough code coverage for
I checked that it was the same for
The other tests bring full code coverage. Factorizing code between |
I was thinking about mixin classes that the test client and the async test client would use, but I'm not sure it's worth it. It would make the code more DRY, but not that much and at the cost of more complexity. Maybe the async test client should live in a separate |
Hmm it looks like https://github.com/vinissimus/async-asgi-testclient is just what I needed. |
|
||
@pytest.fixture | ||
def async_test_client_factory() -> AsyncTestClientFactory: | ||
return functools.partial( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This partial is redundant (and probably the whole fixture too)
Summary
This PR adds
AsyncTestClient
, an async equivalent of TestClient. TheTestClient
runs in a background thread in order to let the application run in the main thread, while theAsyncTestClient
runs in a background task in the same thread as the application.Currently,
AsyncTestClient
is almost a duplication ofTestClient
, with the replacement of the BlockingPortal with a TaskGroup. I'm not sure if/how some code could be shared.See #2935.
Checklist