Pytest(13)命令行参数–tb的使用
2023-06-13 09:12:43 时间
前言
pytest 使用命令行执行用例的时候,有些用例执行失败的时候,屏幕上会出现一大堆的报错内容,不方便快速查看是哪些用例失败。
--tb=style
参数可以设置报错的时候回溯打印内容,可以设置参数(auto/long/short/line/native/no)
–tb=style
pytest -h
查看命令行参数,关于 --tb=style
参数的使用方式
> pytest -h
--tb=style traceback print mode (auto/long/short/line/native/no).
style 的值可以设置6种打印模式:auto/long/short/line/native/no
–tb=no
先写个简单的pytest用例,让他断言报错
def test_01():
result = "hello"
expected = "world"
assert result == expected
命令行执行pytest
此时屏幕上会显示整个用例的回溯信息
../test_1.py::test_01 FAILED [100%]
case/test_1.py:11 (test_01)
hello != world
Expected :world
Actual :hello
<Click to see difference>
def test_01():
result = "hello"
expected = "world"
> assert result == expected
E AssertionError: assert 'hello' == 'world'
../test_1.py:15: AssertionError
Assertion failed
=================================== FAILURES ===================================
___________________________________ test_01 ____________________________________
加上 --tb=no
参数执行
collecting ...
case/test_1.py ⨯ 100% ██████████
--tb=no
是不显示报错的回溯内容
–tb=line
line 模式使用一行输出所有的错误信息
collecting ...
/Users/jkc/PycharmProjects/apiAutomatic/case/test_1.py:15: AssertionError: assert 'hello' == 'world'
case/test_1.py ⨯ 100% ██████████
–tb=short
short 模式显示断言报错的位置,不显示用例前面的代码
collecting ...
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_01 ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
case/test_1.py:15: in test_01
assert result == expected
E AssertionError: assert 'hello' == 'world'
E - world
E + hello
case/test_1.py ⨯ 100% ██████████
其他
–tb=auto 有多个用例失败的时候,只打印第一个和最后一个用例的回溯信息 –tb=long 输出最详细的回溯信息 –tb=short 输入assert的一行和系统判断内容 –tb=line 使用一行显示错误信息 –tb=native 只输出python标准库的回溯信息 –tb=no 不显示回溯信息
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/166347.html原文链接:https://javaforall.cn
相关文章
- lint-md-cli:一款检查中文 Markdown 编写格式规范的命令行工具
- Pytest(17)运行未提交的git(pytest-picked)
- Pytest(6)重复运行用例pytest-repeat「建议收藏」
- Pytest(16)随机执行测试用例pytest-random-order「建议收藏」
- linux查看iostat_ios命令行怎么打开
- pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
- pytest学习和使用5-Pytest和Unittest中的断言如何使用?
- pytest学习和使用11-Pytest如何使用自定义标记mark?
- pytest学习和使用14-Pytest用例执行结果有哪几种状态?
- python中argparse 命令行参数解析包
- python-Django-命令行工具
- Go语言flag包:命令行参数解析
- 学习执行Linux命令行,拥抱技术新生活(c执行linux命令行)
- 使用Linux命令行复制文件(linux下复制文件命令)
- Linux控制台输出:重新解放终端命令行(linux输出到终端)
- 深入浅出:使用Redis命令行查看数据(redis命令行查看数据)
- 行模式进入Redis命令行模式的方法(进入redis命令)
- Oracle备份管理:命令行方式(oracle备份命令行)
- Linux命令行下的网络配置实践(linux命令行网络设置)
- 深入探讨Oracle关闭数据库的命令行操作.(oracle关闭数据库命令)
- 命令行连接外网MySQL数据库流程与指南(cmd连接外网mysql)
- 从命令行进入MySQL数据库(cmd命令进mysql)