pytest接口执行生成pytest-html报告,接口执行失败报告不显示代码解决方法:
在site-packages文件夹下找到pytest_html文件夹,pytest_html文件夹下打开plugin.py文件,在plugin.py找到pytest_runtest_makereport()函数,接着该函数底部加入如下代码:
import pytest
@pytest.mark.hookwrapper
def pytest_runtest_makereport():
outcome = yield
report = outcome.get_result()
if report.when == ‘call’ and report.passed is False:
for i, v in enumerate(report.longrepr.reprtraceback.reprentries[0].lines[::-1]): # 逆向遍历
if not v.startswith(‘E’):
index = len(report.longrepr.reprtraceback.reprentries[0].lines) - i
report.longrepr.reprtraceback.reprentries[0].lines
= report.longrepr.reprtraceback.reprentries[0].lines[index:]
break
https://www.jianshu.com/p/ee3412cf3694