pytest的默认配置pytest.ini文件

  • 在实际使用时,pytest.ini 文件有中文会报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 154: illegal multibyte sequence

解决方法:
点击倒数第二行的报错,进入iniconfig/init.py模块,找到其前面一行代码的open()函数,在open函数中中增加 encoding='utf-8'参数

[pytest]
# 命令行的参数,用空格隔开
addopts = -vs -n 2 --reruns 2 --reruns-delay 2 --alluredir "./myAllureReport"
# 测试用例的路径,默认为执行pytest命令时当前的文件目录及子目录下的所有符合规则的用例
testpaths = ./
#文件名的规则,改成aaa_*.py那就是只会执行aaa_开头的文件
python_files = test_*.py
#类名的规则,效果与python_files设置一样
python_classes = Test*
#方法名的规则
python_functions = test

# 设置控制台日志输出
log_cli = 1   # 调试时可设置为1,批量跑用例则建议关闭,可能会影响性能
log_cli_level = DEBUG
log_cli_date_format = %Y-%m-%d-%H-%M-%S
log_cli_format = %(asctime)s - [%(filename)s] - %(module)s - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s

# 设置日志文件写入
log_file_level = DEBUG
log_file = ./log/log.log
log_file_format = %(asctime)s - [%(filename)s] - %(module)s - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s
log_file_date_format = %Y-%m-%d-%H-%M-%S

#设置用例的分组
markers =
    login: longin
    lesson_a_list: lesson_a_list
    create_lesson: create_lesson
    Fail_retry
    hello
  • addopts这个参数的意思是,设置了这一项,我们在每次执行的时候就不用去写pytest -vs了,可以直接写pytest就能显示出详细信息

-vs 在控制台显示详细信息
-n 表示多线程或者分布式运行测试用例 (pytest-xdist)
--reruns 2 --reruns-delay 2 执行失败后重试2次,每次间隔 2s
--alluredir "./myAllureReport" 执行任务时生成测试报告数据放置在myAllureReport文件下
更多详细参数见:https://www.cnblogs.com/DeryKong/p/16158462.html

  • testpaths = ./ 这个设置就是说pytest执行用例的文件夹,我的后面没有添加文件夹名就是当前项目的所有文件夹

  • python_files = test_.py这个设置意思就是只会执行以test_开头的python文件,这个设置是可以改的,比如我改成aaa_.py那就是只会执行aaa_开头的文件

  • python_classes = Test* 这个就是设置pytest执行的类名的规则,同上面的python_files设置一样,支持改变pytest的默认规则

  • python_functions = test  这个就是设置pytest执行的方法名的规则,同上面的python_files设置一样,支持改变pytest的默认规则

参考文档:http://www.zzvips.com/article/197081.html

posted @ 2022-04-28 13:44  DeyouKong  阅读(306)  评论(0编辑  收藏  举报