mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[5.2.x] Added SimpleTestCase.enterContext() on Python < 3.11.
This reverts commit47a618d45cand uses a solution similar toed4f83782dinstead.
This commit is contained in:
@@ -404,6 +404,10 @@ class SimpleTestCase(unittest.TestCase):
|
||||
def enterClassContext(cls, cm):
|
||||
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):
|
||||
"""
|
||||
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.lookups import Exact
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
from django.utils.version import PY311
|
||||
|
||||
from .models import Comment, Tenant, User
|
||||
|
||||
@@ -557,10 +556,4 @@ class CompositePKFilterTupleLookupFallbackTests(CompositePKFilterTests):
|
||||
feature_patch = patch.object(
|
||||
connection.features, "supports_tuple_lookups", False
|
||||
)
|
||||
if PY311:
|
||||
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)
|
||||
self.enterContext(feature_patch)
|
||||
|
||||
Reference in New Issue
Block a user