美文网首页
pytest-pytest.main

pytest-pytest.main

作者: C1R2 | 来源:发表于2020-09-29 22:17 被阅读0次

1.pytest命令行方式 终端
pass

2.通过python代码执行 pytest.main()
1.直接执行pytest.main() 【自动查找当前目录下,以test_开头的文件或者以_test结尾的py文件】
2.设置pytest的执行参数 pytest.main(['--html=./report.html','test_login.py'])【执行test_login.py文件,并生成html格式的报告】
main()括号内可传入执行参数和插件参数,通过[]进行分割,[]内的多个参数通过‘逗号,’进行分割

运行目录及子包下的所有用例  pytest.main(['目录名'])
运行指定模块所有用例  pytest.main(['test_reg.py'])
运行指定模块指定类指定用例  pytest.main(['test_reg.py::TestClass::test_method'])  冒号分割

-m=xxx: 运行打标签的用例
-reruns=xxx,失败重新运行
-q: 安静模式, 不输出环境信息
-v: 丰富信息模式, 输出更详细的用例执行信息
-s: 显示程序中的print/logging输出
--resultlog=./log.txt 生成log
--junitxml=./log.xml 生成xml报告

'''
import pytest
if name == 'main': # 生成python-html报告
pytest.main(['--reruns', '3', '--reruns-delay', '5', '-s', '-v', '--html=Outputs/reports/report.html']) # OutPuts/reports是项目文件

'''

需要安装 pytest – html 插件;
pip install pytest-html

pytest 可以生成多种样式的结果:
生成 JunitXML 格式的测试报告,命令:–junitxml=path
生成 ResultLog 格式的测试报告,命令:–resultlog=report/log.txt
生成 Html 格式的测试报告,命令:–html=OutPuts/reports/report.html(相对路径)

if name == 'main': # 生成python-html报告
pytest.main(['-s', '-v', '--html=OutPuts/reports/report.html'])

图片.png

相关文章

  • pytest-pytest.main

    1.pytest命令行方式 终端pass 2.通过python代码执行 pytest.main()1.直接执行p...

网友评论

      本文标题:pytest-pytest.main

      本文链接:https://www.haomeiwen.com/subject/xbroghtx.html