Pytest简介
1.可集成CI环境(Jenkins 等)
2.支持参数化,重复执行,部分执行,测试跳过
3. 支持单元测试,功能测试
4.其文件名必须以“test_”开头
5. 测试类以Test开头,并且不能带有 init 方法
6. 除了有setup/teardown,还能更自由的定义fixture装载测试用例(暂未理解)
2.Pytest安装
# 安装
pip install –U pytest
# 查看安装版本
pip show pytest
或者 pytest –version
3.Pytest运行
# test_class.py
Class TestClass:
def test_one(self):
x = “this”
assert ‘h’ in x
def test_one(self):
x = “hello”
assert hasattr(x, ‘check’)
3.1 运行测试用例
# cd 进入到test_class.py 所在的文件夹,
运行其中所有的测试用例: pytest 或者 py.test
指定:
-q 用于指定运行的文件
pytest –q test_class.py
pytest –s test_class.py::test_answer
简单的测试用例:



__________________________________________
BY:HW-ZZR







































苏公安网备 32011402010933号