vendredi 26 mai 2017

Python mocking logging while retaining log output

I have a series of unit/integration tests which using the python logging module. I would like to test that the right things are logged when appropriate which I can achieve using the mock module as follows:

@mock.patch('logging.Logger.info')

However, when I do this the actual logging is stopped (for obvious reasons!) and this is useful for me to debug why my tests are working etc.

My question is as follows: Is there a way in why I can mock out logging calls so I can assert they have been called with the expected arguments but still keep the logging functionality?

Cheers, Jack

Aucun commentaire:

Enregistrer un commentaire