Skip to content

API Reference¤

AssertInefficientQuery¤

If the Duplicate, Similar, and Slow queries exceed the specified values, it is a test utility that fails.

Usage¤

name description available value
num If the duplication, Similar threshold, and query exceed num, the test fails. Optional[int]
seconds If the query exceeds the specified time, the test fails. Optional[int]
ignore_patterns This is a list of SQL Patterns to ignore.This is a list of SQL Patterns to ignore. List[str]

Example¤

assert Duplicate or Similar
from django.test import TestCase
  from django_query_capture.test_utils import AssertInefficientQuery


class AssertInefficientQueryTests(TestCase):
  def test_assert_inefficient_query(self):
    with AssertInefficientQuery(num=19):
      self.client.get('/api/reporter')  # /api/reporter duplicate query: 20, so raise error
assert Slow
from django.test import TestCase
  from django_query_capture.test_utils import AssertInefficientQuery


class AssertInefficientQueryTests(TestCase):
  def test_assert_inefficient_query(self):
    with AssertInefficientQuery(seconds=1):
      self.client.get('/api/reporter')  # /api/reporter api took more than a second. so raise error

Last update: January 26, 2022