pytest测试框架(四) conftest和pytest.ini配置文件
2022/9/9 23:23:27
本文主要是介绍pytest测试框架(四) conftest和pytest.ini配置文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
conftest文件
- 是本地的插件库,其中的hook函数和fixture将作用于该文件所在的目录以及所有子目录
- conftest文件名不能换,进行文件数据共享,放在不同的位置起着不同的范围共享
pytest.ini
pytest的主配置文件,可以改变pytest的默认行为,有很多可配置的选项,放在项目根目录下
常用配置:
1、addopts
作用:addopts参数可以更改默认命令行选项,当我们在cmd或Terminal输入一堆指令去执行用例的时候,就可以用该参数代替了,省去重复性的敲命令工作。命令行只需要输入pytest即可
--reruns=1:用例失败重跑一次
-p no:warnings, :不在结果中输出用例的告警信息
2、配置项testpaths
testpaths是相对于根目录的路径,限定测试用例的搜索范围。只有在命令行执行pytest未指定文件目录参数或测试用例标识符时,该选项才生效。
3、mark标记说明
markers =
weibo: this is weibo page
toutiao: toutiao
xinlang: xinlang
4、log_cli 是否开启打印日志
格式:log_cli=True 或False(默认),或者log_cli=1 或 0 ;log_cli=1 可以看到哪个package下的哪个module下的哪个测试用例是否passed还是failed;
log_cli = 1
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S
5、可以修改或者添加这个用例收集规则
python_files = test_* _test test
python_classes = test* test*
python_functions = test_* test*
[pytest] # mark # 命令行参数 addopts = -v --reruns=1 --count=2 --html=reports.html --self-contained-html -n=auto markers = weibo: this is weibo page toutiao: toutiao xinlang: xinlang xfail_strict = true testpaths = xdist_study python_files = test*.py python_classes = Test* python_functions = test_* log_level : INFO log_format : [%(asctime)s] [%(levelname)s]-[%(filename)s]: [%(module)s]: [%(funcName)s]: [%(lineno)d]: %(message)s log_date_format : %Y-%m-%d %H:%M:%S log_cli = 1 log_cli_level : INFO log_cli_format : [%(asctime)s] [%(levelname)s]-[%(filename)s]: [%(module)s]: [%(funcName)s]: [%(lineno)d]: %(message)s log_cli_date_format : %Y-%m-%d %H:%M:%S log_file : log/testresult.log log_file_level : DEBUG log_file_format : [%(asctime)s] [%(levelname)s]-[%(filename)s]: [%(module)s]: [%(funcName)s]: [%(lineno)d]: %(message)s log_file_date_format : %Y-%m-%d %H:%M:%S
这篇关于pytest测试框架(四) conftest和pytest.ini配置文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升
- 2024-05-08代码报错不用愁,CodeGeeX一键完成代码修复、错误解释的功能上线了!
- 2024-05-08今天开始程序员不用再发愁写commit message了,全部由CodeGeeX自动完成!