Detect blocking calls in coroutines during tests using BlockBuster #3486
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
BlockBuster is a library to detect harmful blocking calls done in the async event loop (when activated, it raises an error if a blocking call is done).
It is just a few lines to integrate with pytest.
Globally,
httpx
is a good citizen and the only blocking call it detected ismimetypes.guess_type
inRequest
constructor.mimetypes
has a global cache so this blocking call is only done once.Solutions for this would be:
mimetypes.guess_type
in a threadI've also seen blocking calls made when using HTTPS but there seems to be no unit tests for async+TLS.
Checklist