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

前端 未结 11 727
谎友^
谎友^ 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:58

    You should use mocking, as someday You might want to change Your logger to a, say, database one. You won't be happy if it'll try to connect to the database during nosetests.

    Mocking will continue to work even if standard output will be suppressed.

    I have used pyMox's stubs. Remember to unset the stubs after the test.

提交回复
热议问题