pytest-dev / pytest-django

A Django plugin for pytest.
https://pytest-django.readthedocs.io/
Other
1.33k stars 341 forks source link

Add `pattern` argument to django_assert_num_queries fixture #1040

Closed qarlosh closed 8 months ago

qarlosh commented 1 year ago

This optional argument allows to filter the queries to take into account for the assertion.

It may be useful to check for the count of only certain queries. For example, a use case of mine is to skip SAVEPOINT queries by using:

NO_SAVEPOINT_PATTERN=r'(?!^(ROLLBACK TO |RELEASE )?SAVEPOINT [`"].+[`"]$)'
...
with django_assert_num_queries(n, pattern=NO_SAVEPOINT_PATTERN):
   ...
bluetech commented 1 year ago

It will be better to propose this change to Django's version first.