mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #31056 -- Allowed disabling async-unsafe check with an environment variable.
This commit is contained in:
parent
635a3f8e6e
commit
c90ab30fa1
5 changed files with 47 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import sys
|
||||
from unittest import skipIf
|
||||
from unittest import mock, skipIf
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
|
||||
|
@ -39,3 +40,13 @@ class AsyncUnsafeTest(SimpleTestCase):
|
|||
)
|
||||
with self.assertRaisesMessage(SynchronousOnlyOperation, msg):
|
||||
self.dangerous_method()
|
||||
|
||||
@mock.patch.dict(os.environ, {'DJANGO_ALLOW_ASYNC_UNSAFE': 'true'})
|
||||
@async_to_sync
|
||||
async def test_async_unsafe_suppressed(self):
|
||||
# Decorator doesn't trigger check when the environment variable to
|
||||
# suppress it is set.
|
||||
try:
|
||||
self.dangerous_method()
|
||||
except SynchronousOnlyOperation:
|
||||
self.fail('SynchronousOnlyOperation should not be raised.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue