pytest_runtest_makereport()获取两个参数,item和call.从item,我可以找到我为此测试创建的funcarg,并且从call中,我可以找到异常信息(如果有的话):
def pytest_runtest_makereport (item, call):
my_funcarg = item.funcargs['name']
my_funcarg.excinfo = call.excinfo
Run Code Online (Sandbox Code Playgroud)
不幸的是,填充了两个失败和跳过的excinfo.为了区分,我需要查看pytest_report_teststatus()的report参数:
def pytest_report_teststatus (report):
if report.when == 'call':
if report.failed:
failed = True
elif report.skipped:
skipped = True
else:
passed = True
Run Code Online (Sandbox Code Playgroud)
这是很好的信息,但我无法将其与我为测试创建的funcarg相关联.我查看了report参数(一个TestReport报告),我找不到任何方法可以回到传递给pytest_runtest_makereport()的项目,或者我创建的funcarg.
我在哪里可以访问这两个?
有一些未记录的非官方方法,钩子实现可以与其他钩子实现交互,例如对其结果进行后处理.在您的具体案例中,您可能会执行以下操作:
@pytest.mark.tryfirst
def pytest_runtest_makereport(item, call, __multicall__):
rep = __multicall__.execute()
# your code follows and you can use rep.passed etc.
return rep
Run Code Online (Sandbox Code Playgroud)
笔记:
多线程 API很少真正,我怀疑可能有针对您的用例的解决方案,不需要它.
HTH,Holger
| 归档时间: |
|
| 查看次数: |
3123 次 |
| 最近记录: |