pytest-断言语句
pytest 语句 断言
2023-09-11 14:14:23 时间
pytest允许在测试用例中使用标准的python断言,如下:
# test_case.py中的内容
def foo(x, y):
return x + y
def test_01():
assert foo(3, 4) == 8
本例中的函数期望返回一个固定的值。如果该断言失败了,你会看到该函数的返回值:
$ pytest test_assert1.py
============================= test session starts ==============================
platform darwin ‐‐ Python 3.7.6, pytest‐4.2.1, py‐1.7.0, pluggy‐0.8.1
rootdir: /Users/liuke/test/demo, inifile:
collected 1 item
test_case.py F [100%]
=================================== FAILURES ===================================
________________________________ test_function _________________________________
def test_function():
> assert foo(3, 4) == 8
E assert 7 == 8
E + where 7 = foo()
test_case.py:5: AssertionError
=========================== 1 failed in 0.07 seconds ===========================
pytest支持显示常见的子表达式的值,包括调用,属性,比较以及二元和一元运算符。(参看Demo
of Python failure reports with purest 这允许你使用你习惯的python的在不丢失内省信息的情况下
构造代码。(什么是内省信息?更详细的内部输出信息?) 如果你为断言指定了输出信息,那么不会
输出任何内省信息,而是在traceback中直接输出指定的信息:
assert a % 2 ==0, "value was odd, should be even"
更多断言内省信息请参考Advanced assertion introspection
最后: 下方这份完整的软件测试视频学习教程已经整理上传完成,朋友们如果需要可以自行免费领取 【保证100%免费】
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!
相关文章
- pytest控制函数运行函数
- Python测试框架Pytest的基础入门
- 【软件测试】Pytest必会技巧(二)
- 技术面试没过,居然是没有用pytest测试框架
- 超详细从入门到精通,pytest自动化测试框架实战-钩子函数(五)
- Python接口自动化系列--pytest入门
- 就是那么轻松的掌握测试框架pytest(上)
- Appium+Pytest+Allure实现APP自动化测试,小试牛刀
- Selenium+Pytest自动化测试框架实战
- pytest-断言语句
- Pytest 自动化测试框架
- 【使用Pytest重构项目】Pytest简介与基本使用
- Pytest单元测试框架实战之setup_function和teardown_function
- pytest+allure+jenkins
- pytest:中文文档+插件列表