I want to ensure that a certain condition in my code causes a log message to be written to the django log. How would I do this with the Django unit testing framework?
Is there a place where I can check logged messages, similarly to how I can check sent emails? My unit test extends django.test.TestCase.
Using the
mockmodule for mocking the logging module or the logger object. When you’ve done that, check the arguments with which the logging function is called.For example, if you code looks like this:
it would look like: