1
0
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 commit 47a618d45c and uses
a solution similar to ed4f83782d instead.
This commit is contained in:
Natalia
2025-07-16 14:08:57 -03:00
committed by nessita
parent fcc7c12f80
commit a76587531b
2 changed files with 5 additions and 8 deletions

View File

@@ -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

View File

@@ -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)