首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为每个测试更改pytest-html报告中显示的路径

如何为每个测试更改pytest-html报告中显示的路径
EN

Stack Overflow用户
提问于 2019-03-25 21:14:19
回答 1查看 587关注 0票数 1

我正在使用pytest-html来生成html报告。但在我的报告中,显示了每个测试用例运行的完整路径。我只希望显示类名和测试用例名称。

在conftest.py文件中

代码语言:javascript
复制
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
  pytest_html = item.config.pluginmanager.getplugin('html')
  outcome = yield
  report = outcome.get_result()
  report.description = str(item.function.__doc__)
  extra = getattr(report, 'extra', [])
  if report.when == 'call':
      # always add url to report
      extra.append(pytest_html.extras.url('http://www.example.com/'))
      xfail = hasattr(report, 'wasxfail')
      if (report.skipped and xfail) or (report.failed and not xfail):
          # only add additional html on failure
          extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
      report.extra = extra



@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
  pytest_html = item.config.pluginmanager.getplugin('html')
  outcome = yield
  report = outcome.get_result()
  report.description = str(item.function.__doc__)
  extra = getattr(report, 'extra', [])
  if report.when == 'call':
      # always add url to report
      extra.append(pytest_html.extras.url('http://www.example.com/'))
      xfail = hasattr(report, 'wasxfail')
      if (report.skipped and xfail) or (report.failed and not xfail):
          # only add additional html on failure
          extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
      report.extra = extra

实际结果:显示每个测试的完整路径

预期:只需要类名和测试用例名称

EN

回答 1

Stack Overflow用户

发布于 2019-11-04 23:57:57

您可能可以使用os.environ.get('PYTEST_CURRENT_TEST')

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55338633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档