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

前端 未结 11 743
谎友^
谎友^ 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 02:13

    Fortunately this is not something that you have to write yourself; the testfixtures package provides a context manager that captures all logging output that occurs in the body of the with statement. You can find the package here:

    http://pypi.python.org/pypi/testfixtures

    And here are its docs about how to test logging:

    http://testfixtures.readthedocs.org/en/latest/logging.html

提交回复
热议问题