【原文链接】Pytest----pytest-sugar 执行过程中显示进度条

Pytest-sugar是一款用来改善控制台显示的插件,增加了进度条显示,使得在用例执行过程中可以看到进度条,而且进度条是根据用例是否通过标注不同颜色,用例通过标记为绿色,用例失败则标记为红色,非常醒目。 首先使用如下命令安装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

执行pytest命令结果如下,可以发现在test_demo.py 后面跟着打印了若干个对号,同时又一段条形图,在控制台根据用例是否通过显示为绿色或者红色。

(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>

文章链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: