接口框架第二篇—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+Playwright+Pytest+BDD,用FSM打造高效测试框架
python·pytest·bdd·playwright·fsm
小白上线*^_^*10 小时前
Pytest 自动化测试框架速通指南(二)
软件测试·pytest·python测试框架·ai测试基础
Logintern091 天前
pytest的AST 断言重写
pytest
Tinyfacture2 天前
接口自动化之添加商品(pytest)
python·测试工具·自动化·pytest
ji_shuke4 天前
从零深入:基于 Playwright + Pytest + Allure 的企业级 Web 端到端自动化测试框架实战
前端·自动化测试·docker·jenkins·pytest·allure·playwright
祉猷并茂,雯华若锦5 天前
Selenium+Pytest自动化测试框架实战
selenium·测试工具·pytest
祉猷并茂,雯华若锦7 天前
Pytest+Selenium自动化测试:失败自动截图集成Allure报告
selenium·测试工具·pytest
我的xiaodoujiao10 天前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest
一孤程14 天前
Pytest+Selenium搭建自动化框架-保姆级实战教程
selenium·自动化·pytest
名字还没想好☜17 天前
用 pytest fixture 组织可维护的测试:告别一堆重复的 setUp
数据库·python·oracle·pytest·测试