(一)pytest框架搭建

一、pytest框架环境搭建

1)安装pytest

   使用pip install -U pytest命令安装pytest,安装成功后pytest --version查看版本号

2)命令行可切换到对应的目录下执行脚本

 

 

3)配置文件,通过配置pytest.ini文件可以自定义命令行参数,设置脚本所在的文件、配置搜索脚本、类、函数名格式,如下截图

 

 

 

默认情况下为:

 

4)报告生成

   安装报告插件pip install -U pytest-html,运行模式为pytest --html=report.html

5)可指定case运行

 

 

 

 

 6)多进程运行cases

  安装插件 pip install -U pytest-xdist

  启动NUM个进程运行脚本 pytest  scripts.py -n NUM

7)运行失败的用例可进行重新执行用例

  安装插件 pip install -U pytest -retunfailures

  运行模式(NUM表示重试的次数):pytest script.py --reruns NUM

8)显示print内容

  在运行测试脚本时,为了调试或打印一些内容,我们会在代码中加一些print内容,但是在运行pytest时,这些内容不会显示出来。如果带上-s,就可以显示了

  运行模式:pytest script.py -s

posted @ 2021-06-15 22:32  啊洽  阅读(925)  评论(0编辑  收藏  举报