You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say For some reason I remove the line PostHistory.objects.create(post=post).
Now the test fails with the number of queries being incorrect (1 instead of 2). But in order to debug this using the following test, I'd have to either comment out the num_queries assertion, or have a separate test for just testing the query count, but that's a solution we don't really want, as there'll always be a test case that tests the logic, but doesn't really check if the queries match (you could have n-queries inside if-statement for example).
As a potential solution for this I was thinking of having a way to not fail the test (only for development), but rather only display the message as a warning.
I think ideally, we could add a CLI flag in the lines of --no-fail-on-django-query-count or something similar.
I'm happy to work on this, just wanted to see if there's any interest in adding something like that, or if there's a better solution to this issue.
The text was updated successfully, but these errors were encountered:
pytest-django uses Django's assertNumQueries, which doesn't support this, so you'd need to propose this to Django.
As for my own opinion, I think this usecase is a bit too niche to be worth the extra mental overhead. You can implement such a fixture yourself in a local conftest.py file without too much effort using Django's CaptureQueriesContext. Adding support for --no-fail-on-django-query-count in a custom fixture is very easy too using a pytest_addoption hook.
If you implement this, make sure to post the snippet here for anyone else who might want this :)
Let's say we've got a following test:
This test would pass of course just fine.
Let's say For some reason I remove the line
PostHistory.objects.create(post=post)
.Now the test fails with the number of queries being incorrect (1 instead of 2). But in order to debug this using the following test, I'd have to either comment out the num_queries assertion, or have a separate test for just testing the query count, but that's a solution we don't really want, as there'll always be a test case that tests the logic, but doesn't really check if the queries match (you could have n-queries inside if-statement for example).
As a potential solution for this I was thinking of having a way to not fail the test (only for development), but rather only display the message as a warning.
I think ideally, we could add a CLI flag in the lines of
--no-fail-on-django-query-count
or something similar.I'm happy to work on this, just wanted to see if there's any interest in adding something like that, or if there's a better solution to this issue.
The text was updated successfully, but these errors were encountered: