当前位置:网站首页>一、unittest框架和pytest框架的区别
一、unittest框架和pytest框架的区别
2022-07-25 09:27:00 【圣诞礼盒】
1.用例编写规则
unittest:提供了testcase测试用例、testsuite测试套件、testfixture测试固件或夹具、testloader测试加载器、testrunner测试运行器。必须遵守以下规则:
(1)测试文件必须先导入import unittest
(2)测试类必须继承unittest.TestCase
(3)测试方法必须以test开头
pytest:它是python的第三方测试框架,基于unittest的扩展框架,必须遵守以下规则:
(1)测试文件名必须以test_开头或_test结尾
(2)测试类命令必须以Test开头
(3)测试方法必须以test开头
2.用例的前置和后置
unittest:
setUp/tearDown 在每个用例之前或之后运行一次
打开浏览器,加载网页/关闭网页
setUpClass和tearDownClass 在每个类运行之前或之后运行一次
创建数据库连接,创建日志对象/关闭数据库连接,销毁日志对象
setUpModule和tearDownModule 在每个门模块之前和之后运行一次
pytest:
方法级:
setup_mmothod/teardown_mothod 在方法之前和之后
setup/teardown
函数级:
setup_function/teardown_function 在函数之前和之后
类级:
setup_class/teardown_class 在类之前和之后
模块级:
setup_module/teardown_module 在模块之前和之后
还有:还可以在函数之前加@pytest.fixture()装饰器
3.断言
unittest:assertTure、assertEqual、assertln
pyutest:assert
4.报告
unittest:htmltestrunner
pytest:插件:pytest-HTML,allure
5.失败重跑
unittest:没有
pytest:pytest-rerunfailures插件
6.数据驱动
unittest:ddt
pytest:@pytest.mark.parametrize装饰器
7.用例分类执行
unittest:默认执行所有,也可以通过testsuite来执行部分用例,或者-k参数
pytest:@pytest.mark
边栏推荐
猜你喜欢

mysql历史数据补充新数据

emmet语法速查 syntax基本语法部分

VLAN的配置及其应用(以华为eNSP为例)
![[necessary for growth] Why do I recommend you to write a blog? May you be what you want to be in years to come.](/img/f5/e6739083f0dce8da1d09d078321633.png)
[necessary for growth] Why do I recommend you to write a blog? May you be what you want to be in years to come.

Detailed explanation of MySQL database

修改mysql的分组报错Expression #1 of SELECT list is not in GROUP

关于slf4j log4j log4j2的jar包配合使用的那些事

小程序企业发放红包功能

Subtotal of rospy odometry sinkhole

ROS distributed operation -- launch file starts nodes on multiple machines
随机推荐
Pytorch 张量列表转换为张量 List of Tensor to Tensor 使用 torch.stack()
oracle 解析同名xml 问题
多线程——静态代理模式
常用类的小知识
TCP传输
Selenium 等待元素出现与等待操作可以执行的条件
cookie and session
IO流中的输出流
切换 shell 命令行终端(bash/zsh)后,conda 无法使用: command not found
VSCode Latex Workshop 设置 XeLatex 编译
Reflection 反射
@Import, conditional and @importresource annotations
Set creation and common methods
复现 ASVspoof 2021 baseline RawNet2
RedisUtil
关闭brew执行命令时的自动更新
SSM整合(简单的图书管理系统来整合SSM)
message from server: “Host ‘xxx.xxx.xxx.xxx‘ is not allowed to connect to this MySQL server“
安装 oh my zsh
@Import,Conditional和@ImportResourse注解