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
Last year I needed to figure out how to assert if a logging level was called. I tried a few things and came up with the solution to mock the _LOGGER.<level> and then assert if logmock was called.
I have noticed that you can use a self.assertLogs(self, logger, level) to check if a message was logged. Since when we are testing we don't really care about what message was logged but if the message was logging we should replace every amock.patch('opsdroid.core._LOGGER.exception') as logmock with the self.assertLogs.
This should make the tests a bit more readable and easier to maintain in the future. This Issue is also great for new contributors since it's quite easy to implement.
Last year I needed to figure out how to assert if a logging level was called. I tried a few things and came up with the solution to mock the
_LOGGER.<level>
and then assert if logmock was called.I have noticed that you can use a
self.assertLogs(self, logger, level)
to check if a message was logged. Since when we are testing we don't really care about what message was logged but if the message was logging we should replace everyamock.patch('opsdroid.core._LOGGER.exception') as logmock
with theself.assertLogs
.This should make the tests a bit more readable and easier to maintain in the future. This Issue is also great for new contributors since it's quite easy to implement.
For a better explanation check the example:
Old style: test_main.py:132-136
Refactored test
If you need any help with this issue make sure to check out gitter channel.
The text was updated successfully, but these errors were encountered: