[dechin@dechin-manjaro pytest]$ python3 -m pip install pytest-htmlCollecting pytest-htmlDownloading pytest_html-3.1.1-py3-none-any.whl (14 kB)Collecting pytest-metadataDownloading pytest_metadata-1.11.0-py2.py3-none-any.whl (10 kB)Requirement already satisfied: pytest!=6.0.0,>=5.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest-html) (6.2.1)Requirement already satisfied: attrs>=19.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest!=6.0.0,>=5.0->pytest-html) (20.3.0)Requirement already satisfied: py>=1.8.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest!=6.0.0,>=5.0->pytest-html) (1.9.0)Requirement already satisfied: toml in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest!=6.0.0,>=5.0->pytest-html) (0.10.1)Requirement already satisfied: packaging in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest!=6.0.0,>=5.0->pytest-html) (20.4)Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest!=6.0.0,>=5.0->pytest-html) (0.13.1)Requirement already satisfied: iniconfig in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest!=6.0.0,>=5.0->pytest-html) (1.1.1)Requirement already satisfied: six in /home/dechin/anaconda3/lib/python3.8/site-packages (from packaging->pytest!=6.0.0,>=5.0->pytest-html) (1.15.0)Requirement already satisfied: pyparsing>=2.0.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from packaging->pytest!=6.0.0,>=5.0->pytest-html) (2.4.7)Installing collected packages: pytest-metadata, pytest-htmlSuccessfully installed pytest-html-3.1.1 pytest-metadata-1.11.0安装成功后,执行如下指令,可以在当前目录下生成一个指定文件名的html文件,如下图所示,就比较全面且美观的展示了测试中的信息:
[dechin@dechin-manjaro pytest]$ py.test --html=pytest_report.html=========================================== test session starts ============================================platform linux -- Python 3.8.5, pytest-6.2.2, py-1.9.0, pluggy-0.13.1rootdir: /home/dechin/projects/2021-python/pytest, configfile: pytest.iniplugins: cov-2.11.1, metadata-1.11.0, html-3.1.1collected 1 itemtest_random_number.py .[100%]--------- generated html file: file:///home/dechin/projects/2021-python/pytest/pytest_report.html ----------============================================ 1 passed in 0.51s =============================================不过在问题数量并不是很多的情况下,直接看命令行输出也是比较方便的 。
pytest覆盖率测试在一个python仓库中我们有可能有非常多的函数、类和文件等,为了保障结果的准确性,我们需要能够给出一个可信的覆盖率测试的结论,只有当覆盖率达到100%时,我们才能认为测试工作已经比较全面的考虑 。当然,覆盖率100%的测试,其实并不能保障100%的不出问题,这就是另外的话题了 。首先我们又需要补充安装一个组件pytest-cov:
[dechin@dechin-manjaro pytest]$ python3 -m pip install pytest-covCollecting pytest-covDownloading pytest_cov-2.11.1-py2.py3-none-any.whl (20 kB)Collecting coverage>=5.2.1Downloading coverage-5.4-cp38-cp38-manylinux2010_x86_64.whl (245 kB)|████████████████████████████████| 245 kB 15 kB/s Requirement already satisfied: pytest>=4.6 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest-cov) (6.2.1)Requirement already satisfied: attrs>=19.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest>=4.6->pytest-cov) (20.3.0)Requirement already satisfied: packaging in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest>=4.6->pytest-cov) (20.4)Requirement already satisfied: iniconfig in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest>=4.6->pytest-cov) (1.1.1)Requirement already satisfied: toml in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest>=4.6->pytest-cov) (0.10.1)Requirement already satisfied: py>=1.8.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest>=4.6->pytest-cov) (1.9.0)Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pytest>=4.6->pytest-cov) (0.13.1)Requirement already satisfied: six in /home/dechin/anaconda3/lib/python3.8/site-packages (from packaging->pytest>=4.6->pytest-cov) (1.15.0)Requirement already satisfied: pyparsing>=2.0.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from packaging->pytest>=4.6->pytest-cov) (2.4.7)Installing collected packages: coverage, pytest-covSuccessfully installed coverage-5.4 pytest-cov-2.11.1然后在当前目录下执行以下指令:
以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!
「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助:- js实现文件下载功能 html图片按钮代码
- 自己制作一个网站的方法 html5制作网页教程
- 浪漫的html表白源代码 网页表白代码大全
- html页面获取url参数 jquery获取url中的参数有哪些
- 讲解html中title标签的作用 html标题代码
- 网页设计菜单栏导航实例 html5导航栏代码
- 分享文件转换工具类 html转换成word文档
- html左图右文布局方法 html左右布局模板
- c语言二维数组定义和赋值 随机数c语言代码
- html简易计算器代码 javascript计算器代码