前言

pytest 运行全部用例的时候,在控制台会先显示用例的运行结果(.或F), 用例全部运行完成后最后把报错信息全部一起抛出到控制台。

这样我们每次都需要等用例运行结束,才知道为什么报错,不方便实时查看报错信息。

pytest-instafail 插件可以在运行用例的时候,需实时查看用例报错内容,这样方便跟踪问题。

--instafail

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

>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参数,方便实时查看报错内容

>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参数,看起来更直观

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

最新文章

  1. resumablejs 分块上传 断点续传
  2. spring--基本介绍
  3. Linux--文件查找命令
  4. gcc 4.8.3 install centos
  5. Python操作Mysql实例代码教程在线版(查询手册)
  6. Android开发系列(十八):自己定义控件样式在drawable目录下的XML实现
  7. ICMP--ping--Traceroute
  8. CSS 去掉inline-block间隙的几种方法
  9. (一)SQLite与SQL语句基础
  10. ConfirmCancelDialog【确认取消对话框】
  11. how2j网站前端项目——天猫前端(第一次)学习笔记8
  12. .netcore webapi 在startup中读取配置字符串
  13. PAT甲题题解-1007. Maximum Subsequence Sum (25)-求最大子区间和
  14. DDA画线算法
  15. 修改socket缓冲区大小
  16. k8s中secret解析
  17. misaka and last order SCU - 4489 (筛法的灵活应用)
  18. 【Spark】源码分析之SparkContext
  19. from module import 和 import 的区别
  20. 安装 SQL Server 2008 和管理工具 SQL Server 2008 management studio 及相关问题解决

热门文章

  1. netty如何进行单元测试
  2. python图片转码为base64
  3. 《搭建个人Leanote云笔记本》
  4. Noip2017 Day2 T1 奶酪
  5. Kubernetes调度流程与安全(七)
  6. Mqtt协议 服务器交互
  7. MATLAB 编译器的使用
  8. python中库引用与import
  9. 突发!美商务部宣布封禁微信,TikTok——面对科技封锁,如何应对
  10. archaius(3) 配置管理器