美文网首页
(十二)pytest.ini

(十二)pytest.ini

作者: Sandra_liu | 来源:发表于2021-08-03 19:13 被阅读0次

1、配置pytest命令行运行参数


#addopts = -v --reruns=1 --html=report.html --self-contained-html
#addopts = -v --reruns=1 --html=report.xml
#testpaths = ./test_login.py
testpaths = test_login.py

1.1、-rsxX -l --tb=short -strict

# addopts = -rsxX  -l --tb=short -strict
# -rsxX表示pytest报告所有测试用例被跳过、预计失败、预计失败但实际通过的原因
# -l表示pytest报告所有失败测试的堆栈中的局部变量。
# --tb表示简化堆栈回溯信息,只保留文件和行数。
# -strict表示禁止使用未在配置文件中注册的标记。

1.2、markers

#注册标记
#markers=
   #smoke: Run the webtest case
   #bbb: Run the api case

1.3、log_cli

#控制台日志
#log_cli=1/0

1.4、xfail_strict

# xfail_strict=true
# xfail_strict表示实际通过的测试用例也被报告为失败

1.5、minversion

# minversion表示知道的pytest的最低版本号

1.6、morecursedirs

# morecursedirs表示忽略某些目录

1.7、添加多个命令行参数

# 空格分隔,可添加多个命令行参数
# addopts = -v --reruns=1 --html=report.html --self-contained-html

1.8、testpaths

# testpaths表示指定测试目录
# testpaths = .//test_login.py

1.9、python_files

# 指定模块
#python_files = test_*.py  或者  *_test.py

1.10、python_classes

# 指定类
#python_classes = Test_*

1.11、python_functions

# 指定方法
#python_functions = test_ *

1.12、

#避免两个目录下的文件重名,需要添加__init__.py

2、实践:执行当前路径下的某个模块中的某个方法,并且生成html报告

[pytest]
addopts = -v --reruns=1 --html=report.html --self-contained-html
testpaths = .\\
python_files = test_login.py
python_functions = test_assert_001

测试结果:


image.png

测试报告:


image.png

相关文章

网友评论

      本文标题:(十二)pytest.ini

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