Search code examples
pythonloggingpython-unittest

Test that a function doesn't create a log entry


I want to test that a function doesn't create a log entry.

with self.assertLogs() as logs:
    function_that_logs_nothing()

But this fails because assertLogs() checks for log entries. If no logs are done it raise an exception. Makes sense.

Is there something like assertNotLogs()?


Solution

  • In Python 3.10 a assertNoLogs() exists.