Skip to content

Instantly share code, notes, and snippets.

@leopard627
Created December 10, 2019 05:59
Show Gist options
  • Save leopard627/113a6ec2c2901b620e07443974537cdd to your computer and use it in GitHub Desktop.
Save leopard627/113a6ec2c2901b620e07443974537cdd to your computer and use it in GitHub Desktop.
django 에서 테스트 케이스 돌릴때 쿼리 같이 뽑는 방법 :P
## reference
## https://stackoverflow.com/questions/13162771/django-how-to-see-sql-query-when-running-tests
from django.db import connection, reset_queries
from django.test import override_settings, TransactionTestCase
class TransactionTests(TransactionTestCase):
@override_settings(DEBUG=True)
def test_sql(self):
reset_queries()
try:
# Code that uses the ORM goes here
except Exception as e:
pass
self.assertEqual(connection.queries, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment