Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Simplified a test by using CapturedQueriesContext

  • Loading branch information...
commit 068b1e045f9b022495f662c80dd820aced116aec 1 parent 671757b
@akaariai akaariai authored
Showing with 7 additions and 10 deletions.
  1. +7 −10 tests/queries/
17 tests/queries/
@@ -6,14 +6,13 @@
import pickle
import unittest
-from django.conf import settings
from django.core.exceptions import FieldError
from django.db import DatabaseError, connection, connections, DEFAULT_DB_ALIAS
from django.db.models import Count, F, Q
from django.db.models.sql.where import WhereNode, EverythingNode, NothingNode
from django.db.models.sql.datastructures import EmptyResultSet
from django.test import TestCase, skipUnlessDBFeature
-from django.test.utils import str_prefix
+from django.test.utils import str_prefix, CaptureQueriesContext
from django.utils import six
from .models import (
@@ -1848,16 +1847,14 @@ def test_ticket8597(self):
class ExistsSql(TestCase):
- def setUp(self):
- settings.DEBUG = True
def test_exists(self):
- self.assertFalse(Tag.objects.exists())
+ with CaptureQueriesContext(connection) as captured_queries:
+ self.assertFalse(Tag.objects.exists())
# Ok - so the exist query worked - but did it include too many columns?
- self.assertTrue("id" not in connection.queries[-1]['sql'] and "name" not in connection.queries[-1]['sql'])
- def tearDown(self):
- settings.DEBUG = False
+ self.assertEqual(len(captured_queries), 1)
+ qstr = captured_queries[0]
+ id, name = connection.ops.quote_name('id'), connection.ops.quote_name('name')
+ self.assertTrue(id not in qstr and name not in qstr)
class QuerysetOrderedTests(unittest.TestCase):

0 comments on commit 068b1e0

Please sign in to comment.
Something went wrong with that request. Please try again.