Generic 「runtest」 hooks
所有的runTest相關鉤收到pytest.Item對象。
pytest_runtest_protocol(項目,nextitem)[源]
implements the runtest_setup/call/teardown protocol for the given test item, including capturing exceptions and calling reporting hooks.
Parameters:
item – test item for which the runtest protocol is performed.
nextitem – the scheduled-to-be-next test item (or None if this is the end my friend). This argument is passed on to pytest_runtest_teardown().
Return boolean:
True if no further hook implementations should be invoked.
pytest_runtest_setup(項目)[來源]
called before pytest_runtest_call(item).
pytest_runtest_call(項目)[來源]
called to execute the test item.
pytest_runtest_teardown( item,nextitem)[來源]
called after pytest_runtest_call.
Parameters: nextitem – the scheduled-to-be-next test item (None if no further test item is scheduled). This argument can be used to perform exact teardowns, i.e. calling just enough finalizers so that nextitem only needs to call setup-functions.
pytest_runtest_makereport(項目,調用)【來源】
return a _pytest.runner.TestReport object for the given pytest.Item and _pytest.runner.CallInfo.
爲了更深入的瞭解,你可以看看_pytest.runner這些掛鉤的默認實現,也許還_pytest.pdb與_pytest交互。捕獲和其輸入/輸出捕獲,以便在發生測試故障時立即進入交互式調試。
報告的_pytest.terminal特別使用報告掛鉤來打印有關測試運行的信息。
看起來你需要在pytest上修改一些模糊的函數。試圖看一下代碼,並且在調用該函數時看起來並不明顯。不過,也許有一種比monkeypatching更清潔,更兼容的解決方案。 – Hector
在賞金到期之前,我沒有時間想出一個工作示例,但看起來像這樣做的鉤子是:['pytest_runtest_protocol'](http://doc.pytest.org/en/latest/ writing_plugins.html#_pytest.hookspec.pytest_runtest_protocol) –