Fix few things related to query_counter context manager:
- Improve doc - Fix the fact that the context was modifying the initial profiling_level in case it was != 0 - Ignores 'killcursors' to fix flaky test that were impacted by killcursors queries (#1869)
This commit is contained in:
@@ -4714,18 +4714,27 @@ class QuerySetTest(unittest.TestCase):
|
||||
for i in range(100):
|
||||
Person(name="No: %s" % i).save()
|
||||
|
||||
with query_counter() as q:
|
||||
self.assertEqual(q, 0)
|
||||
people = Person.objects.no_cache()
|
||||
with query_counter() as q:
|
||||
try:
|
||||
self.assertEqual(q, 0)
|
||||
people = Person.objects.no_cache()
|
||||
|
||||
[x for x in people]
|
||||
self.assertEqual(q, 1)
|
||||
[x for x in people]
|
||||
self.assertEqual(q, 1)
|
||||
|
||||
list(people)
|
||||
self.assertEqual(q, 2)
|
||||
list(people)
|
||||
self.assertEqual(q, 2)
|
||||
|
||||
people.count()
|
||||
self.assertEqual(q, 3)
|
||||
except AssertionError as exc:
|
||||
db = get_db()
|
||||
msg = ''
|
||||
for q in list(db.system.profile.find())[-50:]:
|
||||
msg += str([q['ts'], q['ns'], q.get('query'), q['op']])+'\n'
|
||||
msg += str(q)
|
||||
raise AssertionError(str(exc) + '\n'+msg)
|
||||
|
||||
people.count()
|
||||
self.assertEqual(q, 3)
|
||||
|
||||
def test_cache_not_cloned(self):
|
||||
|
||||
@@ -5053,7 +5062,7 @@ class QuerySetTest(unittest.TestCase):
|
||||
{"$ne": "%s.system.indexes" % q.db.name}})[0]
|
||||
|
||||
self.assertFalse('$orderby' in op['query'],
|
||||
'BaseQuerySet must remove orderby from meta in boolen test')
|
||||
'BaseQuerySet must remove orderby from meta in boolean test')
|
||||
|
||||
self.assertEqual(Person.objects.first().name, 'A')
|
||||
self.assertTrue(Person.objects._has_data(),
|
||||
|
||||
Reference in New Issue
Block a user