首页 > 技术文章 > pytest用法---学习篇1

siguadd 2021-05-19 14:39 原文

一、pytest运行规则:

pytest可以收集所有以test_*.py文件,Test开头的类,和以test_开头的函数和方法,都能识别成测试用例。

当然也可以改变这个的识别规则

二、常用参数

  • -k 满足表达式的都会执行。
  • -collect-only 只负责收集测试用例,不会执行,可以看有多少个用例
  • -m  只执行加标签的测试用例    @pytest.mark.标签名

三、测试用例的执行顺序

前面的用例会先于后面的用例执行

如果要指定顺序,需要插件pytest-ordering

四、导出依赖包

env1\bin\python -m pip freeze > requirements.txt

env2\bin\python -m pip install -r requirements.txt

五、conftest.py文件

可以共享数据,方法,fixture方法放置在这个文件下

六、pytest.ini配置文件

[pytest]
#addopts = -p no:warnings -s --alluredir=./report/result
addopts = --alluredir ./report/result
#--reruns 3 --reruns-delay=2
#--html=./report/report.html
#--alluredir ./report/result

testpaths = testcase
python_files = test_excel*.py

 

推荐阅读