• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
redrose2100
帮助1

【原文链接】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>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggbiec
系列文章
更多 icon
同类精品
更多 icon
继续加载