Testing Async Views
A snippet showing how to test asynchronous Django views.
# Result (tests/test_async.py)
from django.test import AsyncClient, SimpleTestCase
from django.urls import reverse
class AsyncViewTest(SimpleTestCase):
async def test_async_view(self):
client = AsyncClient()
res = await client.get(reverse("async-ping"))
assert res.status_code == 200
Explanation:
-
Use
AsyncClientandSimpleTestCase(Django ≥ 3.2) to test async views. -
Mark test as
async defto await calls.
- Category Testing
- Total Views 1090
- Last Modified 19 March, 2026
- Tags #testing #async #views #unittest
Previous snippet
Testing API Views with DRF
Next snippet