12.python开源——pytest自动化测试框架
来源:互联网 发布:单例设计模式php 编辑:程序博客网 时间:2024/06/05 00:15
1 下载链接
https://docs.pytest.org/en/latest/getting-started.html
或者使用pip安装
命令如下:
pip install pytest
更新命令:pip install -U pytest
查看版本pytest —version
2 pytest使用
2.1 基本测试
创建test_func.py
内容如下:
def func(x):return x +1
def test_answer(): assert func(3) == 5
然后执行
#pytest test_func.py
collected 1items
test_func.py F
===================================FAILURES ===================================
_________________________________test_answer __________________________________
> def test_answer(): assert func(3) == 5
E assert 4 == 5
E + where 4 = func(3)
test_func.py:3: AssertionError
=========================== 1 failedin 0.02 seconds ===========================
测试结束,该用例测试失败。
因为函数结果因为4,不等于5嘛。
2.2 运行多个测试
pytest会在当前目录中运行所有文件以及子文件夹,需要以test_*.py或*_test.py文件。遵循标准规则。
-q参数表示quiet
创建test_class.py内容如下:
class TestClass:
def test_one(self):
x = "this"
assert 'h'in x
def test_two(self):
x = "hello"
assert hasattr(x,'check')
测试结果如下:
1failed, 1 passed in 0.02 seconds
2.3 请求一个临时文件
创建test_temp.py内如如下:
def test_needsfiles(tmpdir):
print (tmpdir)
assert 0
然后执行,会报错
在测试函数中列出了tmpdir。
2.4 查看内置的参数
# pytest --fixtures
- 12.python开源——pytest自动化测试框架
- python 测试框架 pytest
- excle+pytest+jenkins+allure接口自动化测试框架
- Python单元测试框架Pytest——如何生成测试报告
- Python pytest测试
- 【Pytest】python单元测试框架pytest简介
- 用pytest做服务端自动化协议测试
- Python自动化测试框架参考
- python自动化测试框架nose
- python自动化测试,自动化框架及工具
- 一个好用的python测试框架(pytest)及其CI设置
- python测试模块pytest之坑
- 【开发也是好测试】(三)—pytest fixture scope
- 使用mongodb+pytest+allure+jenkins构建api接口自动化测试
- 软件测试框架——自动化测试框架(专题)
- 软件测试框架——自动化测试框架
- 开源Web自动化测试框架——Watir试用手记
- 开源Web自动化测试框架——Watir试用手记
- Java之I/O流
- 如何在EditText中设置固定图片——Android移动开发 .
- Retrofix2使用详解
- 关于表单数据的传输问题
- 我的java入门
- 12.python开源——pytest自动化测试框架
- FCFS和SJF进程调度算法的实现
- 简单实现网页登录框中的“记住我”
- Mybatis与Hibernate的区别
- 第八届蓝桥杯B组C/C++
- C#138课的主要内容
- HDU1542 Atlantis 线段树扫描面积
- 浏览器同源政策及其规避方法
- PlaidCTF CTF 2015 pwn160