Created
December 10, 2019 05:59
-
-
Save leopard627/113a6ec2c2901b620e07443974537cdd to your computer and use it in GitHub Desktop.
django 에서 테스트 케이스 돌릴때 쿼리 같이 뽑는 방법 :P
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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