@@ -491,6 +491,75 @@ If you use type annotations, you can annotate the fixture like this::
491491 ...
492492
493493
494+ .. fixture :: django_assert_num_queries_all_connections
495+
496+ ``django_assert_num_queries_all_connections ``
497+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
498+
499+ .. py :function :: django_assert_num_queries_all_connections(num, info = None )
500+
501+ :param num: expected number of queries
502+
503+ This fixture allows to check for an expected number of DB queries on all
504+ your database connections.
505+
506+ If the assertion failed, the executed queries can be shown by using
507+ the verbose command line option.
508+
509+ It wraps ``django.test.utils.CaptureQueriesContext `` and yields the wrapped
510+ ``DjangoAssertNumAllConnectionsQueries `` instance.
511+
512+ Example usage::
513+
514+ def test_queries(django_assert_num_queries_all_connections):
515+ with django_assert_num_queries_all_connections(3) as captured:
516+ Item.objects.using("default").create('foo')
517+ Item.objects.using("logs").create('bar')
518+ Item.objects.using("finance").create('baz')
519+
520+ assert 'foo' in captured.captured_queries[0]['sql']
521+
522+ If you use type annotations, you can annotate the fixture like this::
523+
524+ from pytest_django import DjangoAssertNumAllConnectionsQueries
525+
526+ def test_num_queries(
527+ django_assert_num_queries: DjangoAssertNumAllConnectionsQueries,
528+ ):
529+ ...
530+
531+
532+ .. fixture :: django_assert_max_num_queries_all_connections
533+
534+ ``django_assert_max_num_queries_all_connections ``
535+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
536+
537+ .. py :function :: django_assert_max_num_queries_all_connections(num, info = None )
538+
539+ :param num: expected maximum number of queries
540+
541+ This fixture allows to check for an expected maximum number of DB queries on all
542+ your database connections.
543+
544+ It is a specialized version of :fixture: `django_assert_num_queries_all_connections `.
545+
546+ Example usage::
547+
548+ def test_max_queries(django_assert_max_num_queries_all_connections):
549+ with django_assert_max_num_queries_all_connections(2):
550+ Item.objects.using("logs").create('foo')
551+ Item.objects.using("finance").create('bar')
552+
553+ If you use type annotations, you can annotate the fixture like this::
554+
555+ from pytest_django import DjangoAssertNumAllConnectionsQueries
556+
557+ def test_max_num_queries(
558+ django_assert_max_num_queries_all_connections: DjangoAssertNumAllConnectionsQueries,
559+ ):
560+ ...
561+
562+
494563.. fixture :: django_capture_on_commit_callbacks
495564
496565``django_capture_on_commit_callbacks ``
0 commit comments