一、pytest框架介绍

1. 测试框架的分类:

  进行测试执行操作:Selenium、Appium、Requests

  测试用例管理及执行:pytest、Unitest、Nose
  测试报告:Allure
  数据驱动:DDT
  环境部署及持续集成:Docker、Jenkins

 

2. pytest 简介:

  pytest 是 unittest 框架的一种扩展,比 unittest 框架更简洁、更高效,用于编写和执行测试代码。

  pytest 框架特点:

  (1)pytest 直接使用 Python 内置的 assert 语句进行断言,不需要使用 unittest 框架中的 self.assert* 等方法。

  (2)pytest 能够自动识别测试模块和测试函数,不需要与 unittest 框架一样进行声明一个必须继承 unittest.TestCase 的测试类,但是声明的测试方法和测试类需要满足 pytest 的规则。

  (3)pytest 框架中最核心的模块是 fixture 模块,能够实现对象、参数、用例等一系列的管理操作。

  (4)pytest 能够兼容 unittest 框架、nose 框架等测试套件的运行。

  (5)pytest 具有丰富的插件。

 

3. 安装方式: pip install pytest  

  查看方式:pip show pytest

 

4 pytest 执行用例规则:
  (1)文件名以 test_*.py 或 *_test.py 命名

  (2)以 test_ 开头的函数

  (3)以 Test 开头的类,不能包含 __init__ 方法

  (4)以 test_ 开头的类里面的方法

  (5)所有的包 package 必须有 __init__.py 文件

posted @ 2023-09-01 14:43  努力的小测试  阅读(112)  评论(0编辑  收藏  举报