Performance: Async test patterns
MEDIUM IMPACT
This affects the responsiveness and speed of running asynchronous tests, impacting developer feedback loop and CI pipeline efficiency.
import pytest import httpx @pytest.mark.asyncio async def test_endpoint(): async with httpx.AsyncClient(app=app, base_url='http://test') as client: response = await client.get('/async-endpoint') assert response.status_code == 200
def test_endpoint(): response = client.get('/async-endpoint') assert response.status_code == 200
| Pattern | Event Loop Usage | Concurrency | Test Suite Runtime | Verdict |
|---|---|---|---|---|
| Synchronous test client | Blocks event loop | No concurrency | Longer runtime | [X] Bad |
| Async test client with await | Non-blocking | Single concurrency | Faster runtime | [!] OK |
| Concurrent async tests with asyncio.gather | Non-blocking | High concurrency | Shortest runtime | [OK] Good |