I am trying to unit test method that calls logging.info
three times – first time it's logging local variables for the method, another two times it's logging messages that get triggered in case a certain condition is fulfilled.
In one of my test cases, logging.info
gets called only once – to log local variables. The other two calls are not supposed to happen. I'm trying to include that in my unit tests but using unittest.mock.Mock.assert_not_called()
is quite naturally out of question because my logging.info
gets called once. (However, I can't test logging.info
message for local variables.)
class Test_create_s3_file(unittest.TestCase):
...
def setUp(self):
self.LOGGER = logging
...
def test_success_basic(self):
# Mocks
self.LOGGER.info = MagicMock()
...
# Calls
...
self.LOGGER.info.assert_not_called()
# Does not work because it has one call for local variables