pycharm 报错 error: unrecognized arguments: --html=./report.html

报错截图

在这里插入图片描述

代码:

import pytest # 引入pytest包



def test_a(): # test开头的测试函数
    print("------->test_a")
    assert (1) # 断言成功

def test_b():
    print("------->test_b")
    assert (0) # 断言失败

if __name__ == '__main__':
    pytest.main(["--html=./report.html","test_demo1.py"])

原因是没有安装pytest-html

pip install pytest-html

安装了后还是报错

解决办法:
进入File-Setting-Project Interpreter -点击+ 输入pytest-html 安装

在这里插入图片描述
再次运行,
在这里插入图片描述

打开report.html,以下就是测试报告

在这里插入图片描述或者在命令窗口执行命令 :pytest --html=report/report.html 也可以生成报告,要在工程的目录下执行命令

在这里插入图片描述