[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安裝成功后,執(zhí)行如下指令,可以在當(dāng)前目錄下生成一個(gè)指定文件名的html文件,如下圖所示,就比較全面且美觀的展示了測(cè)試中的信息:
[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 =============================================不過在問題數(shù)量并不是很多的情況下,直接看命令行輸出也是比較方便的 。
pytest覆蓋率測(cè)試在一個(gè)python倉(cāng)庫(kù)中我們有可能有非常多的函數(shù)、類和文件等,為了保障結(jié)果的準(zhǔn)確性,我們需要能夠給出一個(gè)可信的覆蓋率測(cè)試的結(jié)論,只有當(dāng)覆蓋率達(dá)到100%時(shí),我們才能認(rèn)為測(cè)試工作已經(jīng)比較全面的考慮 。當(dāng)然,覆蓋率100%的測(cè)試,其實(shí)并不能保障100%的不出問題,這就是另外的話題了 。首先我們又需要補(bǔ)充安裝一個(gè)組件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然后在當(dāng)前目錄下執(zhí)行以下指令:
以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!
「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助:- js實(shí)現(xiàn)文件下載功能 html圖片按鈕代碼
- 自己制作一個(gè)網(wǎng)站的方法 html5制作網(wǎng)頁(yè)教程
- 浪漫的html表白源代碼 網(wǎng)頁(yè)表白代碼大全
- html頁(yè)面獲取url參數(shù) jquery獲取url中的參數(shù)有哪些
- 講解html中title標(biāo)簽的作用 html標(biāo)題代碼
- 網(wǎng)頁(yè)設(shè)計(jì)菜單欄導(dǎo)航實(shí)例 html5導(dǎo)航欄代碼
- 分享文件轉(zhuǎn)換工具類 html轉(zhuǎn)換成word文檔
- html左圖右文布局方法 html左右布局模板
- c語言二維數(shù)組定義和賦值 隨機(jī)數(shù)c語言代碼
- html簡(jiǎn)易計(jì)算器代碼 javascript計(jì)算器代碼
