我有自定義的fixture,它在測試過程中收集有關DB查詢的信息,並且在測試失敗的情況下使用該fixture,我想添加fixture收集的信息來報告。我怎樣才能做到這一點?如何修改特定測試的故障報告
UPDATE
如何,它看起來像:
from contextlib import contextmanager
import db
import pytest
def make_cursor_handler():
...
return cursor_handler, list_with_log
@contextmanager
def wrap_cursor():
old_handler = db.cursor_handler
db.cursor_handler, list_with_log = make_cursor_handler()
yield list_with_log
db.cursor_handler = old_handler
@pytest.yield_fixture
def cursor_fixture():
with wrap_cursor() as log:
yield log #How would I print it inside error report without including it in assert message?
如果可以的話請給一些更多的細節。 –