在写pytest测试用例脚本时,使用print函数来进行打印调试,发现不会打印print语句,原因为pytest
根据pytest文档,pytest的第3版可以在测试中临时禁用捕获:
def test_disabling_capturing(capsys): print('this output is captured') with capsys.disabled(): print('output not captured, going directly to sys.stdout') print('this output is also captured')
如果想实现标准输出,则需要加上 -s来执行测试脚本
pytest - s test_*.py