summaryrefslogtreecommitdiff
path: root/django/test/testcases.py
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2020-03-05 14:26:33 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-03-05 14:29:21 +0100
commit17009e910538b9c3709d302f54c2d10eb245cf38 (patch)
tree05bf934bddd287cbe00e5a8155b24f9b76f26a7e /django/test/testcases.py
parent2f53d324debee680658aed7f22f1aaf81385b1f2 (diff)
Refs #31224 -- Added autoconversion of test async methods.
Diffstat (limited to 'django/test/testcases.py')
-rw-r--r--django/test/testcases.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 23459f22cd..2c24708a3b 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1,3 +1,4 @@
+import asyncio
import difflib
import json
import posixpath
@@ -16,6 +17,8 @@ from urllib.parse import (
)
from urllib.request import url2pathname
+from asgiref.sync import async_to_sync
+
from django.apps import apps
from django.conf import settings
from django.core import mail
@@ -257,6 +260,10 @@ class SimpleTestCase(unittest.TestCase):
getattr(testMethod, "__unittest_skip__", False)
)
+ # Convert async test methods.
+ if asyncio.iscoroutinefunction(testMethod):
+ setattr(self, self._testMethodName, async_to_sync(testMethod))
+
if not skipped:
try:
self._pre_setup()