标签:ini 模块 nbsp 测试的 val 文件名 install self mil
模块的命名要以“test”开头或者“_test.py”结尾
类的命名要以“Test”开头
测试用例的命名要以“test”开头
cmd命令行参数运行:
pytest -x # 遇到第一个失败时,退出执行
pytest --maxfail=2 # 遇到第二个失败时,退出执行
指定模块
pytest test_mod.py # test_mod.py为模块名
指定文件
pytest test_01/ # test_01/ 为路径
pytest -m demo
pytest -m demo # demo为标签名
pytest -rA
-r是输出总结报告,后面跟着的参数是筛选,可以叠加筛选条件
f:失败的
E:出错的
s:跳过执行的
x:跳过执行,并标记为xfailed的
X:跳过执行,并标记为xpassed的
p:测试通过的
P:测试通过,并且有输出信息的;即用例中有print等
a:除了测试通过的,其他所有的;即除了p和P的
A:所有的
使用pytest.main()函数,参数必须放在元组或列表中,参数使用和命令行一致
if __name__ == ‘__main__‘:
pytest.main(["-k","make and not two"])
纯文本格式报告
pytest --resultlog=path
junitxml格式报告
pytest --junitxml=path
html报告(需先安装插件pip install pytest-html)
pytest --html=path
首先要在main函数(执行pytest命令的入口函数,和测试用例文件夹同级)的同级目录下新增一个叫pytest.ini的文件(文件名不能改),然后定义标签
[pytest] # 区域名,固定不能动
markers = # mark标记,固定不能动
skome: describe must be English # 标签名,冒号后面为标签描述,必须为英文
test1:describe must be English
demo:a test for pytest
定义好后在测试类或测试用例前打上标记
@pytest.mark.demo # demo为标签名
可打多个标签
assert 200==100
def test_match(self):
with pytest.raises(ValueError):
myfunc()
如果myfunc()这个函数体(被测试的内容)没有抛出ValueError异常,则断言失败
标签:ini 模块 nbsp 测试的 val 文件名 install self mil
原文地址:https://www.cnblogs.com/handsomesuancaiyu/p/12115343.html