pytest-sugar?執(zhí)行過程中顯示進(jìn)度條的腳本分享
Pytest-sugar是一款用來改善控制臺(tái)顯示的插件,增加了進(jìn)度條顯示,使得在用例執(zhí)行過程中可以看到進(jìn)度條,而且進(jìn)度條是根據(jù)用例是否通過標(biāo)注不同顏色,用例通過標(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ù)用例是否通過顯示為綠色或者紅色。
(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)情況下就是開啟的,若不想使用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使用
無他,主要是安裝了pytest-sugar之后,使用pytest運(yùn)行代碼,風(fēng)格依然沒有變化,在此記錄一下
1. 安裝pytest-sugar
pip install pytest-sugar
2. 運(yùn)行
安裝完成后,通過pytest運(yùn)行代碼,sugar不生效,查看pytest-sugar官方文檔: https://pypi.org/project/pytest-sugar/
發(fā)現(xiàn)pytest-sugar需要有其他依賴(共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)行不生效的原因是:沒有安裝pytest-xdist,安裝后,運(yùn)行生效
3.不使用sugar用法:
py.test -p no:sugar
到此這篇關(guān)于pytest-sugar 執(zhí)行過程中顯示進(jìn)度條的文章就介紹到這了,更多相關(guān)pytest sugar 顯示進(jìn)度條內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Pytest使用logging模塊寫日志的實(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常見用法
- 詳解Pytest測(cè)試用例的執(zhí)行方法
- Python pytest裝飾器總結(jié)(實(shí)例詳解)
- 詳解pytest實(shí)現(xiàn)mark標(biāo)記功能詳細(xì)介紹
相關(guān)文章
python GUI庫圖形界面開發(fā)之PyQt5滑塊條控件QSlider詳細(xì)使用方法與實(shí)例
這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5滑塊條控件QSlider詳細(xì)使用方法與實(shí)例,需要的朋友可以參考下2020-02-02
Python插件virtualenv搭建虛擬環(huán)境
這篇文章主要為大家詳細(xì)介紹了Python插件virtualenv搭建虛擬環(huán)境,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
Django使用paginator插件實(shí)現(xiàn)翻頁功能的實(shí)例
今天小編就為大家分享一篇關(guān)于Django使用paginator插件實(shí)現(xiàn)翻頁功能的實(shí)例,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-10-10
詳解如何使用pandas進(jìn)行時(shí)間序列數(shù)據(jù)的周期轉(zhuǎn)換
時(shí)間序列數(shù)據(jù)是數(shù)據(jù)分析中經(jīng)常遇到的類型,為了更多的挖掘出數(shù)據(jù)內(nèi)部的信息,我們常常依據(jù)原始數(shù)據(jù)中的時(shí)間周期,將其轉(zhuǎn)換成不同跨度的周期,下面以模擬的K線數(shù)據(jù)為例,演示如何使用pandas來進(jìn)行周期轉(zhuǎn)換,感興趣的朋友可以參考下2024-05-05
Pytorch搭建YoloV4目標(biāo)檢測(cè)平臺(tái)實(shí)現(xiàn)源碼
這篇文章主要為大家介紹了Pytorch搭建YoloV4目標(biāo)檢測(cè)平臺(tái)實(shí)現(xiàn)源碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
Python實(shí)現(xiàn)王者榮耀自動(dòng)刷金幣的完整步驟
這篇文章主要介紹了Python實(shí)現(xiàn)王者農(nóng)藥自動(dòng)刷金幣的完整步驟,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01

