pytest-sugar?執(zhí)行過(guò)程中顯示進(jìn)度條的腳本分享
Pytest-sugar是一款用來(lái)改善控制臺(tái)顯示的插件,增加了進(jìn)度條顯示,使得在用例執(zhí)行過(guò)程中可以看到進(jìn)度條,而且進(jìn)度條是根據(jù)用例是否通過(guò)標(biāo)注不同顏色,用例通過(guò)標(biāo)記為綠色,用例失敗則標(biāo)記為紅色,非常醒目。
首先使用如下命令安裝pytest-sugar插件
pip install pytest-sugar
然后準(zhǔn)備比如如下測(cè)試腳本。
def test_1(): print("in test_1") assert 1==1 def test_2(): print("in test_2") assert 1==1 def test_3(): print("in test_3") assert 1==1 def test_4(): print("in test_4") assert 1==1 def test_5(): print("in test_5") assert 1==1 def test_6(): print("in test_6") assert 1==1
執(zhí)行pytest命令結(jié)果如下,可以發(fā)現(xiàn)在test_demo.py 后面跟著打印了若干個(gè)對(duì)號(hào),同時(shí)又一段條形圖,在控制臺(tái)根據(jù)用例是否通過(guò)顯示為綠色或者紅色。
(demo-HCIhX0Hq) E:\demo>pytest Test session starts (platform: win32, Python 3.7.9, pytest 7.2.0, pytest-sugar 0.9.6) benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000) rootdir: E:\demo, configfile: pytest.ini plugins: allure-pytest-2.12.0, assume-2.4.3, attrib-0.1.3, benchmark-4.0.0, rerunfailures-10.2, sugar-0.9.6 collecting ... test_demo.py ?????? 100% ██████████ Results (0.10s): 6 passed (demo-HCIhX0Hq) E:\demo>
當(dāng)安裝了pytest-sugar后默認(rèn)情況下就是開(kāi)啟的,若不想使用pytest-sugar了可以直接卸載或者使用如下命令,也可以禁止使用pytest-sugar。如下所示。
(demo-HCIhX0Hq) E:\demo>pytest -p no:sugar =================== test session starts =================== platform win32 -- Python 3.7.9, pytest-7.2.0, pluggy-1.0.0 benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000) rootdir: E:\demo, configfile: pytest.ini plugins: allure-pytest-2.12.0, assume-2.4.3, attrib-0.1.3, benchmark-4.0.0, rerunfailures-10.2 collected 6 items test_demo.py ...... [100%] ==================== 6 passed in 0.09s ==================== (demo-HCIhX0Hq) E:\demo>
補(bǔ)充知識(shí):
pytest-sugar使用
無(wú)他,主要是安裝了pytest-sugar之后,使用pytest運(yùn)行代碼,風(fēng)格依然沒(méi)有變化,在此記錄一下
1. 安裝pytest-sugar
pip install pytest-sugar
2. 運(yùn)行
安裝完成后,通過(guò)pytest運(yùn)行代碼,sugar不生效,查看pytest-sugar官方文檔: https://pypi.org/project/pytest-sugar/
發(fā)現(xiàn)pytest-sugar需要有其他依賴(lài)(共3個(gè)):
Python 2.7, 3.4 or newer
pytest2.9.0 or newer
pytest-xdist 1.14 or above if you want the progress bar to work while running tests in parallel
我運(yùn)行不生效的原因是:沒(méi)有安裝pytest-xdist,安裝后,運(yùn)行生效
3.不使用sugar用法:
py.test -p no:sugar
到此這篇關(guān)于pytest-sugar 執(zhí)行過(guò)程中顯示進(jìn)度條的文章就介紹到這了,更多相關(guān)pytest sugar 顯示進(jìn)度條內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Pytest使用logging模塊寫(xiě)日志的實(shí)例詳解
- pytest測(cè)試框架+allure超詳細(xì)教程
- pytest官方文檔解讀之安裝和使用插件的方法
- pytest使用@pytest.mark.parametrize()實(shí)現(xiàn)參數(shù)化的示例代碼
- Pytest執(zhí)行unittest TestSuite(測(cè)試套件)的實(shí)現(xiàn)方法
- python單測(cè)框架之pytest常見(jiàn)用法
- 詳解Pytest測(cè)試用例的執(zhí)行方法
- Python pytest裝飾器總結(jié)(實(shí)例詳解)
- 詳解pytest實(shí)現(xiàn)mark標(biāo)記功能詳細(xì)介紹
相關(guān)文章
Django中QuerySet查詢(xún)優(yōu)化之prefetch_related詳解
prefetch_related()和select_related()的設(shè)計(jì)目的很相似,都是為了減少SQL查詢(xún)的數(shù)量,但是實(shí)現(xiàn)的方式不一樣,下面這篇文章主要給大家介紹了關(guān)于Django中QuerySet查詢(xún)優(yōu)化之prefetch_related的相關(guān)資料,需要的朋友可以參考下2022-11-11Python 利用CSV模塊處理數(shù)據(jù)的實(shí)現(xiàn)實(shí)例
CSV文件的一個(gè)主要優(yōu)點(diǎn)是有很多程序可以存儲(chǔ),轉(zhuǎn)換和處理純文本文件,本文主要介紹了Python 利用CSV模塊處理數(shù)據(jù)的實(shí)現(xiàn)實(shí)例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03在python中創(chuàng)建表格的兩種方法實(shí)例
Python 是一種解釋型、面向?qū)ο?、?dòng)態(tài)數(shù)據(jù)類(lèi)型的高級(jí)程序設(shè)計(jì)語(yǔ)言,下面這篇文章主要給大家介紹了關(guān)于如何在python中創(chuàng)建表格的兩種方法,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01python實(shí)現(xiàn)list元素按關(guān)鍵字相加減的方法示例
這篇文章主要介紹了python實(shí)現(xiàn)list元素按關(guān)鍵字相加減的方法,結(jié)合具體實(shí)例形式分析了Python針對(duì)list元素遍歷與運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-06-06Python3 利用face_recognition實(shí)現(xiàn)人臉識(shí)別的方法
這篇文章主要介紹了Python3 利用face_recognition實(shí)現(xiàn)人臉識(shí)別的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03插入排序_Python與PHP的實(shí)現(xiàn)版(推薦)
下面小編就為大家?guī)?lái)一篇插入排序_Python與PHP的實(shí)現(xiàn)版(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05Python request設(shè)置HTTPS代理代碼解析
這篇文章主要介紹了Python request設(shè)置HTTPS代理代碼解析,分享了相關(guān)代碼示例,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-02-02Python統(tǒng)計(jì)文本詞匯出現(xiàn)次數(shù)的實(shí)例代碼
這篇文章主要介紹了Python統(tǒng)計(jì)文本詞匯出現(xiàn)次數(shù),這種問(wèn)題在統(tǒng)計(jì)文本詞匯的次數(shù)時(shí)經(jīng)常會(huì)遇到,今天給大家分享解決方案,通過(guò)實(shí)例代碼給大家講解,需要的朋友可以參考下2020-02-02Python爬蟲(chóng):通過(guò)關(guān)鍵字爬取百度圖片
本文主要介紹了Python爬蟲(chóng):通過(guò)關(guān)鍵字爬取百度圖片的方法。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02