【问题标题】:How to change path displayed in pytest-html report for each test如何更改每个测试的 pytest-html 报告中显示的路径
【发布时间】:2019-03-25 13:14:19
【问题描述】:

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

在我的 conftest.py 文件中

@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

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

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

【问题讨论】:

  • 如果有人知道请告诉我

标签: python-3.x pytest pytest-html


【解决方案1】:

你或许可以使用os.environ.get('PYTEST_CURRENT_TEST')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多