pytest
不会捕获print()
中的stdout
语句(pytest_sessionfinish()
输出)或在其中调用的代码。要获得相同或相似的行为(如位于测试,固定装置等中的print()
语句)的最佳实践是什么?
# conftest.py
def pytest_sessionfinish(session, exitstatus):
print('This wont be captured (like in tests) but output independent of pytest exit status (exitstatus).')
if exitstatus == 0:
print('stdout shall be captured/suppressed in case of overall test PASS.')
else:
print('stdout shall be output in case of overall test FAIL and any other error.')