【问题标题】:How to create a HTML report for pytest?如何为 pytest 创建 HTML 报告?
【发布时间】:2018-06-08 12:55:45
【问题描述】:

我在 Eclipse 中使用 pytest 框架创建了一个项目

class TestClass(object):
    def test_one(self):
        x = "this"
        assert 'h' in x

    def test_two(self):
        x = "hello"
        assert hasattr(x, 'check')

现在,我想为我的项目创建一个 html 报告。我已完成以下操作:

  • 安装了html插件
  • 在 conftest.py 模块中编写以下代码
import pytest

@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    pytest_html = item.config.pluginmanager.getplugin('html')
    outcome = yield
    report = outcome.get_result()

当我运行测试时,我没有得到任何报告。下面是我的预期结果,但没有生成报告

> ============================= test session starts ============================= platform win32 -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0 rootdir: D:\Eclipse1\TFCProject,
> inifile: plugins: ordering-0.5, metadata-1.7.0, html-1.19.0 collected
> 2 items
> 
> TFCPackage\pycheck.py .F                                              
> [100%]
> 
> ================================== FAILURES ===================================
> _____________________________ TestClass.test_two self = <TFCPackage.pycheck.TestClass object at 0x03778AF0>

    def test_two(self):
        x = "hello"
>       assert hasattr(x, 'check')
E       AssertionError: assert False
E        +  where False = hasattr('hello', 'check')

TFCPackage\pycheck.py:13: AssertionError
===================== 1 failed, 1 passed in 0.41 seconds ======================

请指导我,因为我是 pytest 新手

【问题讨论】:

  • pytest --html=report.html?

标签: python pytest pytest-html


【解决方案1】:

如果您想在 Eclipse IDE 中执行此操作,则需要更改您的 Eclipse 配置。

  1. 打开配置

    窗口 -> 首选项 -> PyDev -> PyUnit

  2. 在“测试运行器的参数”部分添加此参数

    --html=reportname.html

将上面的报告名称替换为您选择的报告名称。

请注意,此设置是全局设置,每次在 eclipse 中运行 pytest 时都会生成报告。

【讨论】:

  • 谢谢..它通过在参数列表中放置“--html=reportname.html”来工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-19
  • 2018-04-05
  • 1970-01-01
  • 2017-08-31
  • 1970-01-01
相关资源
最近更新 更多