Pytest----pytest-sugar 执行过程中显示进度条

【原文链接】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>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

redrose2100

您的鼓励是我最大的创作动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值