How should I verify a log message when testing Python code under nose?

前端 未结 11 731
谎友^
谎友^ 2020-12-13 01:12

I\'m trying to write a simple unit test that will verify that, under a certain condition, a class in my application will log an error via the standard logging API. I can\'t

11条回答
  •  再見小時候
    2020-12-13 01:59

    The ExpectLog class implemented in tornado is a great utility:

    with ExpectLog('channel', 'message regex'):
        do_it()
    

    http://tornado.readthedocs.org/en/latest/_modules/tornado/testing.html#ExpectLog

提交回复
热议问题