Pytest 是什么?
- pytest 能够支持简单的单元测试和复杂的功能测试;
- pytest 可以结合 Requests 实现接口测试; 结合 Selenium、Appium 实现自动化功能测试;
- 使用 pytest 结合 Allure 集成到 Jenkins 中可以实现持续集成。
- pytest 支持 315 种以上的插件;
为什么要选择 Pytest
Pytest 安装与准备
Pytest 环境安装
- 前提:本地已配置完成Python环境
- 第一种方式
pip install pytest
- 第二种方式 PyCharm 直接安装
运行第一个脚本
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
运行输入:
D:\Project\WebDemo>pytest test_demo.py
======================================== test session starts ========================================
platform win32 -- Python 3.8.2, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: D:\Project\WebDemo
collected 1 item
test_demo.py F [100%]
============================================= FAILURES ==============================================
____________________________________________ test_answer ____________________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
test_demo.py:7: AssertionError
====================================== short test summary info ======================================
Failed test_demo.py::test_answer - assert 4 == 5
========================================= 1 Failed in 0.08s =========================================
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。