0
我想爲一組測試編寫自定義記錄器,而不對測試做任何重大更改。我想使用像夾具這樣的東西,我可以傳遞給測試方法,並且在測試捕獲stdout和stderr並將其更改爲定製消息的整個持續時間期間,夾具在後臺運行。如何才能做到這一點 ?如何使用在後臺運行的燈具在python中捕獲stdout和stderr
def test_1():
blah
blah
print('Some msg')
blah
assert something, assert_msg
Output:
Some msg (if assert fails, then assertion error too)
我要的是
@fixture
def logger():
capture stdout, stderr
custom_msg = cust_msg(stdout, stderr)
print(custom_msg)
def test_1(logger):
blah
blah
print('Some msg')
blah
assert something, assert_msg
Output:
Custom msg (if assert fails, then custom assertion error too)