1
0
mirror of https://github.com/django/django.git synced 2025-07-03 17:29:12 +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.lookups import Exact
from django.test import TestCase, skipUnlessDBFeature
from django.utils.version import PY311
from .models import Comment, Tenant, User
@ -556,4 +557,10 @@ class CompositePKFilterTupleLookupFallbackTests(CompositePKFilterTests):
feature_patch = patch.object(
connection.features, "supports_tuple_lookups", False
)
self.enterContext(feature_patch)
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)