pythonpython-3.xunit-testingpython-unittest

Python testing: How can I verify that no error logs were thrown?


In my test I want to verify that no error log was done during the test. How do I do that?

I tried with self.assertLogs("", level="ERROR") as error_logs:. This can capture the error logs, but it will also raise if there were no error logs at all.


Solution

  • with self.assertNoLogs("", level="ERROR")

    reference: https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertNoLogs