pytest文档53-命令行实时输出错误信息(pytest-instafail)
时间:2022-07-24
本文章向大家介绍pytest文档53-命令行实时输出错误信息(pytest-instafail),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
前言
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 ======================
- 高性能Java解析器实现过程详解
- Java内存模型深度解读
- Java 实现线程死锁
- Java 四种线程池的用法分析
- 深入了解Java对象序列化
- 在Java EE7框架中使用MongoDB
- 用事实说话,成熟的ORM性能不是瓶颈,灵活性不是问题:EF5.0、PDF.NET5.0、Dapper原理分析与测试手记
- iPhone的Wi-Fi芯片漏洞利用POC公布,赶紧更新系统吧
- No.003 Longest Substring Without Repeating Characters
- 【Spark研究】极简 Spark 入门笔记——安装和第一个回归程序
- 通常Java开发人员如何进行数据排序?
- 消息服务框架使用案例之--大文件上传(断点续传)功能
- Java中三种Set类型用法、性能大比拼
- Android基础总结(5)——数据存储,持久化技术
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法