summaryrefslogtreecommitdiff
path: root/tests/distinct_on_fields
diff options
context:
space:
mode:
authorSrinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి) <srinivasreddy@users.noreply.github.com>2018-08-21 21:47:46 +0530
committerTim Graham <timograham@gmail.com>2018-08-21 12:17:46 -0400
commit233c70f0479beb3bff9027e6cff680882978fd4d (patch)
tree3b557b0703a23b7f96d4a4ce77832b6cbccefd15 /tests/distinct_on_fields
parent201017df308266c7d5ed20181e6d0ffa5832e3e9 (diff)
downloaddjango-233c70f0479beb3bff9027e6cff680882978fd4d.tar.gz
Fixed #29658 -- Registered model lookups in tests with a context manager.
Diffstat (limited to 'tests/distinct_on_fields')
-rw-r--r--tests/distinct_on_fields/tests.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/tests/distinct_on_fields/tests.py b/tests/distinct_on_fields/tests.py
index ae4eb3bd19..6ed73cd75a 100644
--- a/tests/distinct_on_fields/tests.py
+++ b/tests/distinct_on_fields/tests.py
@@ -1,6 +1,7 @@
from django.db.models import CharField, Max
from django.db.models.functions import Lower
from django.test import TestCase, skipUnlessDBFeature
+from django.test.utils import register_lookup
from .models import Celebrity, Fan, Staff, StaffTag, Tag
@@ -100,14 +101,11 @@ class DistinctOnTests(TestCase):
new_name = self.t1.name.upper()
self.assertNotEqual(self.t1.name, new_name)
Tag.objects.create(name=new_name)
- CharField.register_lookup(Lower)
- try:
+ with register_lookup(CharField, Lower):
self.assertCountEqual(
Tag.objects.order_by().distinct('name__lower'),
[self.t1, self.t2, self.t3, self.t4, self.t5],
)
- finally:
- CharField._unregister_lookup(Lower)
def test_distinct_not_implemented_checks(self):
# distinct + annotate not allowed