2
這裏不同的文件我有一個包含tests.py:pytest標準輸出齊平,從測試輸出
import sys
sys.stdout = open('log2.log', 'w')
class TestH5Client:
def test_something(self):
print("Start")
assert True
print("End")
def teardown_class(cls):
print("OK")
我正在我的測試用下面的shell命令
pytest tests.py::TestH5Client::test_something >>log.log
並且我希望log.log包含測試運行信息和log2.log以包含所有打印件,但是log2.log是空
內容log.log(內容是我期望的那樣)的:
內容============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.1.0, py-1.4.33, pluggy-0.4.0
rootdir: C:\Stefans\01.Learning_Python\27.pytest_std_ouput, inifile:
collected 2 items
tests.py .
========================== 1 passed in 0.01 seconds ===========================
log2.log:該文件是空的
期待log2.log內容:
Start
End
OK
所以我的問題是我做錯了什麼,我怎麼能使它這樣工作,謝謝你提前。