2

我正在使用 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

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

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

pytest-html 报告

4

1 回答 1

0

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

于 2019-11-04T15:57:57.180 回答