Created
November 20, 2024 14:18
-
-
Save czue/38762d58588627f57e23a1535a7ad6c8 to your computer and use it in GitHub Desktop.
assertNumQueries example
This file contains 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
from django.test import TransactionTestCase | |
from .services import my_function_that_hits_the_db | |
class MyTest(TransactionTestCase): | |
def test_db_performance(self): | |
# called directly | |
self.assertNumQueries(7, my_function_that_hits_the_db) | |
# used as a context manager | |
with self.assertNumQueries(2): | |
Person.objects.create(name="Aaron") | |
Person.objects.create(name="Beth") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment