My django.request
logger is chatty when there are 4xx and 5xx responses, as per the default. In my test suite, when I test error cases, I find myself silencing the output with a pattern like this in order to avoid changing my LOGGING
setting in test_settings.py:
with self.assertLogs("django.request", level="WARNING"):
response = self.client.get(...
with self.assertContains(
response, "needle", status=HTTPStatus.BAD_REQUEST
)
The reason I’m not thrilled about changing LOGGING
in test_settings.py is that it would be nice to know about unexpected failing requests, which I do find from time to time, where “know about” means they clutter my test output.
That assertLogs
is a little bit of a workaround. I really don’t want to be asserting so much about the logger; I just want to silence the output when the failure is expected.
What patterns are other folks using?