1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

Fixed AttributeError for enterContext() on Python < 3.11.

On Jenkins with Python 3.10:

Traceback (most recent call last):
  File "[...]/python3.10/tests/composite_pk/test_filter.py", line 559, in setUp
    self.enterContext(feature_patch)
AttributeError: 'CompositePKFilterTupleLookupFallbackTests' object has no attribute 'enterContext'
This commit is contained in:
Natalia 2025-07-02 09:15:15 -03:00 committed by nessita
parent a150160c9f
commit 47a618d45c

View File

@ -14,6 +14,7 @@ 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
@ -556,4 +557,10 @@ 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)