From 32d70b2f55b1f74736fd11bc8efce890ad5fa2f0 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 20 Dec 2022 11:10:48 +0100 Subject: Refs #34118 -- Adopted asgiref coroutine detection shims. Thanks to Mariusz Felisiak for review. --- django/test/testcases.py | 5 ++--- django/test/utils.py | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'django/test') diff --git a/django/test/testcases.py b/django/test/testcases.py index c78c2300a7..090a31e7c4 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1,4 +1,3 @@ -import asyncio import difflib import inspect import json @@ -26,7 +25,7 @@ from urllib.parse import ( ) from urllib.request import url2pathname -from asgiref.sync import async_to_sync +from asgiref.sync import async_to_sync, iscoroutinefunction from django.apps import apps from django.conf import settings @@ -401,7 +400,7 @@ class SimpleTestCase(unittest.TestCase): ) # Convert async test methods. - if asyncio.iscoroutinefunction(testMethod): + if iscoroutinefunction(testMethod): setattr(self, self._testMethodName, async_to_sync(testMethod)) if not skipped: diff --git a/django/test/utils.py b/django/test/utils.py index 2b2b92c593..5e5649b0ac 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -1,4 +1,3 @@ -import asyncio import collections import logging import os @@ -14,6 +13,8 @@ from types import SimpleNamespace from unittest import TestCase, skipIf, skipUnless from xml.dom.minidom import Node, parseString +from asgiref.sync import iscoroutinefunction + from django.apps import apps from django.apps.registry import Apps from django.conf import UserSettingsHolder, settings @@ -440,7 +441,7 @@ class TestContextDecorator: raise TypeError("Can only decorate subclasses of unittest.TestCase") def decorate_callable(self, func): - if asyncio.iscoroutinefunction(func): + if iscoroutinefunction(func): # If the inner function is an async function, we must execute async # as well so that the `with` statement executes at the right time. @wraps(func) -- cgit v1.3