Pytest和Allure测试框架-超详细版+实战1

一:pytest的介绍,安装,框架结构,执行方式

1,特点

  1. 简单灵活,容易上手;支持参数化; 测试用例的skip和xfail 处理;
  2. 能够支持简单的单元测试和复杂的功能测试,还可以用来做 selenium/appium等自动化测试、接口自动化测试 (pytest+requests);
  3. pytest具有很多第三方插件,并且可以自定义扩展, 比较好 用的如 pytest-allure(完美html测试报告生成) pytest-xdist (多CPU分发)等;
  4. 可以很好的和jenkins集成;**

2,安装

pytest安装,导入相关依赖库
Pip install –U pytest U表示升级
Pip install sugar
pip install pytest-rerunfailures
Pip install pytest-xdist
Pip install pytest-assume
Pip intall pytest-html …
Pip list查看
Pytest –h 帮助**

3,pytest的框架结构

Pytest框架结构
Import pytest 类似的setup,teardown同样更灵活,还有个session()


Pytest和Allure测试框架-超详细版+实战1_第1张图片
在这里插入图片描述

模块级 (setup_module/
teardown_module) 不在类中的函数有用
函数级 (setup_function/
teardown_function) 不在类中的函数有用
类级 (setup_class/
teardown_class)只在 类中前后运行一次。
方法级 (setup_method/
teardown_methond) 运行在类中方法始末

4,pytest的执行方式

Pytest/py.test(终端,命令行,pycharm可配置pytest方式执行)

    1. Pytest –v (最高级别信息—verbose)
  • 2.pytest -v -s filename
  • 3.Pytest-q (静默)
    (输出打印)
    多种执行方式
    1.pytest将在当前目录及其子目录中运行test _ * .py或* test.py形 式的所有文件。
    2.以test_开头的函数,以Test开头的类,以test_开头的方法。所有包 package都要有_init.py文件。
    3.Pytest可以执行unittest框架写的用例和方法

参考链接
https://blog.csdn.net/qq_42610167/article/details/101204066

你可能感兴趣的:(Pytest和Allure测试框架-超详细版+实战1)