pytest.ini
(1)定义
是pytest单元测试框架的配置文件,实现了改变运行方式等功能
(2)位置
在项目工程的根目录
(3)用法
[pytest]
addopts = -vs --html D:/se_frame/Reports/report.html
testpaths = D:/se_frame/TestCases
python_files = test*
python_classes = Test*
python_functions = test*
markers =
smoke
usermange
product
这的路径必须是绝对路径,不然生成的测试报告路径就有问题
addopts:添加了一些pytest.main()执行时候常用的函数
testpaths:识别D:\se_frame\TestCases的测试用例
python_files:识别以TestCases目录下以test开头的文件
python_classes:识别以Test开头的类
python_functions:识别以test开头的方法
markers:主要是@pytest.mark.xxx要用到它来对测试用例进行分类。比如第一个是冒烟用例
常用函数如下:
"""
pytest参数详解:
-s 表示输出陶氏信息,包括print打印的信息
-v 表示更相信的信息
-vs 一般一起用
-n 支持分布式运行测试用例
-k 根据用例的部分字符串指定测试用例
--html 路径 生成测试报告
"""
实际例子:
pytest.ini不带-vs的输出:
collected 13 items
test_1.py ..........Xs. [100%]
- generated html file: file://D:\se_frame\Cases\MapAaaCases\Reports\report.html -
================== 11 passed, 1 skipped, 1 xpassed in 0.33s ===================
pytest.ini带-vs的输出:
collected 13 items
test_1.py::Testlogin001::test_case_12
启动浏览器
---进入要执行模块的的界面---
---3号用例完成---
---4号用例完成---
---5号用例完成---
---12号用例完成---
XPASS (该功能尚未完善,还在调测中)
退出浏览器
test_1.py::Testlogin001::test_case_13 SKIPPED (test_case_13用例还在...)
test_1.py::Testlogin2::test_case_14
启动浏览器
---进入要执行模块的的界面---
---14号用例完成---
PASSED
退出浏览器
- generated html file: file://D:\se_frame\Cases\MapAaaCases\Reports\report.html -
================== 11 passed, 1 skipped, 1 xpassed in 0.13s ===================