mirror of
https://github.com/django/django.git
synced 2025-07-22 02:29:12 +00:00
[5.2.x] Added SimpleTestCase.enterContext() on Python < 3.11.
This reverts commit 47a618d45c6e40dd59f4cdd46fd5fc7d11626f6d and uses a solution similar to ed4f83782d9f3404ad600f6131ef78244ff1e162 instead.
This commit is contained in:
parent
fcc7c12f80
commit
a76587531b
@ -404,6 +404,10 @@ class SimpleTestCase(unittest.TestCase):
|
|||||||
def enterClassContext(cls, cm):
|
def enterClassContext(cls, cm):
|
||||||
return _enter_context(cm, cls.addClassCleanup)
|
return _enter_context(cm, cls.addClassCleanup)
|
||||||
|
|
||||||
|
# Backport of unittest.TestCase.enterContext() from Python 3.11.
|
||||||
|
def enterContext(self, cm):
|
||||||
|
return _enter_context(cm, self.addCleanup)
|
||||||
|
|
||||||
def settings(self, **kwargs):
|
def settings(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
A context manager that temporarily sets a setting and reverts to the
|
A context manager that temporarily sets a setting and reverts to the
|
||||||
|
@ -14,7 +14,6 @@ from django.db.models import (
|
|||||||
from django.db.models.functions import Cast
|
from django.db.models.functions import Cast
|
||||||
from django.db.models.lookups import Exact
|
from django.db.models.lookups import Exact
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.utils.version import PY311
|
|
||||||
|
|
||||||
from .models import Comment, Tenant, User
|
from .models import Comment, Tenant, User
|
||||||
|
|
||||||
@ -557,10 +556,4 @@ class CompositePKFilterTupleLookupFallbackTests(CompositePKFilterTests):
|
|||||||
feature_patch = patch.object(
|
feature_patch = patch.object(
|
||||||
connection.features, "supports_tuple_lookups", False
|
connection.features, "supports_tuple_lookups", False
|
||||||
)
|
)
|
||||||
if PY311:
|
|
||||||
self.enterContext(feature_patch)
|
self.enterContext(feature_patch)
|
||||||
else:
|
|
||||||
# unittest.TestCase.enterContext() was added in Python 3.11.
|
|
||||||
from django.test.testcases import _enter_context
|
|
||||||
|
|
||||||
_enter_context(feature_patch, self.addCleanup)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user