Python 如何为pytest创建HTML报告?

Python 如何为pytest创建HTML报告?,python,pytest,pytest-html,Python,Pytest,Pytest Html,我已经使用pytest框架在eclipse中创建了一个项目 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插件 在conf

我已经使用pytest框架在eclipse中创建了一个项目

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模块中编写以下代码
当我运行测试时,我没有得到任何报告。下面是我预期的结果,但没有生成任何报告

> ============================= 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 ======================
======================================================================================================平台win32--Python3.6.5,pytest-3.6.0,py-1.5.3,pluggy-0.6.0 rootdir:D:\Eclipse1\tProject,
>inifile:插件:ordering-0.5、metadata-1.7.0、html-1.19.0
>2项
> 
>TFCPackage\pycheck.py.F
> [100%]
> 
>===================================================故障===================================
>测试类。测试两个自=
def测试二(自身):
x=“你好”
>断言hasattr(x,‘检查’)
断言错误:断言错误
E+其中False=hasattr('hello','check')
TFCPackage\pycheck.py:13:AssertionError
=========================1失败,1在0.41秒内通过======================

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

如果您想在EclipseIDE中进行测试,您需要更改Eclipse配置

  • 打开配置

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

  • 在“测试运行程序的参数”一节中添加此参数

    --html=reportname.html

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

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

    pytest--html=report.html
    ?谢谢。它通过将“-html=reportname.html”放在参数列表中工作
    > ============================= 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 ======================