Fixed #31407 -- Adjusted test to avoid coroutine never awaited warning.
This commit is contained in:
parent
26799c6503
commit
590957a0eb
|
@ -269,9 +269,10 @@ class AsyncHandlerRequestTests(SimpleTestCase):
|
||||||
|
|
||||||
async def test_unawaited_response(self):
|
async def test_unawaited_response(self):
|
||||||
msg = (
|
msg = (
|
||||||
"The view handlers.views.async_unawaited didn't return an "
|
"The view handlers.views.CoroutineClearingView.__call__ didn't"
|
||||||
"HttpResponse object. It returned an unawaited coroutine instead. "
|
" return an HttpResponse object. It returned an unawaited"
|
||||||
"You may need to add an 'await' into your view."
|
" coroutine instead. You may need to add an 'await'"
|
||||||
|
" into your view."
|
||||||
)
|
)
|
||||||
with self.assertRaisesMessage(ValueError, msg):
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
await self.async_client.get('/unawaited/')
|
await self.async_client.get('/unawaited/')
|
||||||
|
|
|
@ -51,6 +51,12 @@ async def async_regular(request):
|
||||||
return HttpResponse(b'regular content')
|
return HttpResponse(b'regular content')
|
||||||
|
|
||||||
|
|
||||||
async def async_unawaited(request):
|
class CoroutineClearingView:
|
||||||
"""Return an unawaited coroutine (common error for async views)."""
|
def __call__(self, request):
|
||||||
return asyncio.sleep(0)
|
"""Return an unawaited coroutine (common error for async views)."""
|
||||||
|
# Store coroutine to suppress 'unawaited' warning message
|
||||||
|
self._unawaited_coroutine = asyncio.sleep(0)
|
||||||
|
return self._unawaited_coroutine
|
||||||
|
|
||||||
|
|
||||||
|
async_unawaited = CoroutineClearingView()
|
||||||
|
|
Loading…
Reference in New Issue