接口框架第二篇—unittest/pytest 有什么区别

1.用例编写方法

unittest

1)测试文件必须导入unittest包

2)测试类必须继承unittest.TestCase

3)测试类必须有unittest.main()方法

4)测试方法必须要以test_打头

pytest

1)测试文件名要以test_打头,或者_test结尾

2)测试类名字要以Test打头

3)测试方法名字test_打头

2.用例分类执行

unittest

默认执行全部用例,也可通过加载testsuit,执行部分用例

pytest

通过@pytest.mark方法来标记类和方法,pytest.main()加入参数-m来标记执行标记的类和方法

3.用例的前置和后置

unittest

提供了setUp/tearDown,只能针对所有用例

pytest

pytest的fixture可以任意自定义方法函数

4.参数化

unittest

依赖ddt

pytest

使用@pytest.mark.parametrize装饰器

5.断言

unittest

断言有很多格式,(assertEqual,assertIn,assertTrue,assertFalse)

pytest

pytest只有assert一个表达式

6.生成测试报告

unittest

unittest使用HTMLTestRunner

pytest

pytest-HTML,allure插件

7.失败重跑

unittest

无机制

pytest

pytest-rerunfailures插件可支持失败重跑

相关推荐
黄昏恋慕黎明4 小时前
博客论坛技术迭代
python·pytest
2601_962078236 小时前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
杨女士YRJ7 小时前
python+pytest+01
python·pytest
2601_962078231 天前
Python接口自动化框架:pytest
python·pytest·接口自动化·测试框架·restfulapi
2601_962078191 天前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用
2601_962284503 天前
安卓APP UI自动化测试:Python + UiAutomator2 + pytest + pytest-html
python·pytest·uiautomator2·ui自动化测试·安卓app
2601_962300813 天前
基于pytest的接口自动化测试:使用requests模块的实战项目与接口关联方法详解
接口自动化测试·测试用例·pytest·接口关联·requests模块
2601_962300813 天前
Python + Requests + Pytest + Excel + Allure:接口自动化测试项目实战
python·excel·pytest·allure·requests
11路没有终点4 天前
Pytest 安装、版本与第一个测试用例
测试用例·pytest
11路没有终点5 天前
pytest 参数化与 Mark 标记
pytest