前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >pytest文档53-命令行实时输出错误信息(pytest-instafail)

pytest文档53-命令行实时输出错误信息(pytest-instafail)

作者头像
上海-悠悠
发布2020-09-10 17:43:59
9660
发布2020-09-10 17:43:59
举报

前言

pytest 运行全部用例的时候,在控制台会先显示用例的运行结果(.或F), 用例全部运行完成后最后把报错信息全部一起抛出到控制台。 这样我们每次都需要等用例运行结束,才知道为什么报错,不方便实时查看报错信息。 pytest-instafail 插件可以在运行用例的时候,需实时查看用例报错内容,这样方便跟踪问题。

—instafail

执行全部用例,报错内容等用例运行完成才显示出来

代码语言:javascript
复制
>pytest
============================= test session starts =============================

collected 11 items

test_s.py ..                                                             [ 18%]
test_t.py ...                                                            [ 45%]
test_x.py .F.F                                                           [ 81%]
test_y.py ..                                                             [100%]

================================== FAILURES ===================================
___________________________________ test_02 ___________________________________

    def test_02():
        a = "hello"
        b = "hello world"
>       assert a == b
E       AssertionError: assert 'hello' == 'hello world'
E         - hello
E         + hello world

test_x.py:12: AssertionError
___________________________________ test_04 ___________________________________

    def test_04():
        a = "hello"
        b = "hello world"
>       assert a not in b
E       AssertionError: assert 'hello' not in 'hello world'
E         'hello' is contained here:
E           hello world

test_x.py:24: AssertionError
===================== 2 failed, 9 passed in 1.32 seconds ======================

当用例很多的时候,不方便我们查看具体哪个报错对应哪条用例,加上--instafail参数,方便实时查看报错内容

代码语言:javascript
复制
>pytest --instafail
============================= test session starts =============================

collected 11 items

test_s.py ..                                                             [ 18%]
test_t.py ...                                                            [ 45%]
test_x.py .F

___________________________________ test_02 ___________________________________

    def test_02():
        a = "hello"
        b = "hello world"
>       assert a == b
E       AssertionError: assert 'hello' == 'hello world'
E         - hello
E         + hello world

test_x.py:12: AssertionError

test_x.py .F

___________________________________ test_04 ___________________________________

    def test_04():
        a = "hello"
        b = "hello world"
>       assert a not in b
E       AssertionError: assert 'hello' not in 'hello world'
E         'hello' is contained here:
E           hello world

test_x.py:24: AssertionError

test_y.py ..                                                             [100%]

===================== 2 failed, 9 passed in 1.37 seconds ======================

结合--tb=line参数,看起来更直观

代码语言:javascript
复制
>pytest --instafail --tb=line
============================= test session starts =============================
collected 11 items

test_s.py ..                                                             [ 18%]
test_t.py ...                                                            [ 45%]
test_x.py .F

D:\test_x.py:12: AssertionError: assert 'hello' == 'hello world'

test_x.py .F

D:\test_x.py:24: AssertionError: assert 'hello' not in 'hello world'

test_y.py ..                                                             [100%]

===================== 2 failed, 9 passed in 1.30 seconds ======================
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-09-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • —instafail
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档