1
我有一个测试函数来操纵对象的内部状态。该对象使用logging.info()
记录以下内容。Python:在鼻子/单元测试中使用记录信息?
INFO:root:_change: test light red
INFO:root:_change: test light green
INFO:root:_change: test light yellow
我怎样才能将它纳入鼻子或unittest功能,以便我可以有一个类似的测试呢?
def test_thing():
expected_log_output = "INFO:root:_change: test light red\n" +\
"INFO:root:_change: test light green\n" +\
"INFO:root:_change: test light yellow\n"
run_thing()
assert actual_log_output matches expected_log_output