pytest-sugar?執(zhí)行過程中顯示進度條的腳本分享
Pytest-sugar是一款用來改善控制臺顯示的插件,增加了進度條顯示,使得在用例執(zhí)行過程中可以看到進度條,而且進度條是根據(jù)用例是否通過標注不同顏色,用例通過標記為綠色,用例失敗則標記為紅色,非常醒目。
首先使用如下命令安裝pytest-sugar插件
pip install pytest-sugar
然后準備比如如下測試腳本。
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 后面跟著打印了若干個對號,同時又一段條形圖,在控制臺根據(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>
當安裝了pytest-sugar后默認情況下就是開啟的,若不想使用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>
補充知識:
pytest-sugar使用
無他,主要是安裝了pytest-sugar之后,使用pytest運行代碼,風格依然沒有變化,在此記錄一下
1. 安裝pytest-sugar
pip install pytest-sugar
2. 運行
安裝完成后,通過pytest運行代碼,sugar不生效,查看pytest-sugar官方文檔: https://pypi.org/project/pytest-sugar/
發(fā)現(xiàn)pytest-sugar需要有其他依賴(共3個):
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
我運行不生效的原因是:沒有安裝pytest-xdist,安裝后,運行生效
3.不使用sugar用法:
py.test -p no:sugar
到此這篇關(guān)于pytest-sugar 執(zhí)行過程中顯示進度條的文章就介紹到這了,更多相關(guān)pytest sugar 顯示進度條內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Django中QuerySet查詢優(yōu)化之prefetch_related詳解
prefetch_related()和select_related()的設(shè)計目的很相似,都是為了減少SQL查詢的數(shù)量,但是實現(xiàn)的方式不一樣,下面這篇文章主要給大家介紹了關(guān)于Django中QuerySet查詢優(yōu)化之prefetch_related的相關(guān)資料,需要的朋友可以參考下2022-11-11Python 利用CSV模塊處理數(shù)據(jù)的實現(xiàn)實例
CSV文件的一個主要優(yōu)點是有很多程序可以存儲,轉(zhuǎn)換和處理純文本文件,本文主要介紹了Python 利用CSV模塊處理數(shù)據(jù)的實現(xiàn)實例,具有一定的參考價值,感興趣的可以了解一下2024-03-03python實現(xiàn)list元素按關(guān)鍵字相加減的方法示例
這篇文章主要介紹了python實現(xiàn)list元素按關(guān)鍵字相加減的方法,結(jié)合具體實例形式分析了Python針對list元素遍歷與運算相關(guān)操作技巧,需要的朋友可以參考下2017-06-06Python3 利用face_recognition實現(xiàn)人臉識別的方法
這篇文章主要介紹了Python3 利用face_recognition實現(xiàn)人臉識別的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-03-03Python request設(shè)置HTTPS代理代碼解析
這篇文章主要介紹了Python request設(shè)置HTTPS代理代碼解析,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下2018-02-02Python統(tǒng)計文本詞匯出現(xiàn)次數(shù)的實例代碼
這篇文章主要介紹了Python統(tǒng)計文本詞匯出現(xiàn)次數(shù),這種問題在統(tǒng)計文本詞匯的次數(shù)時經(jīng)常會遇到,今天給大家分享解決方案,通過實例代碼給大家講解,需要的朋友可以參考下2020-02-02