pytest.6.Parametrize Fixture
From: http://www.testclass.net/pytest/parametrizing_fixture/
背景
@pytest.mark.parametrize 装饰器可以让我们每次参数化fixture的时候传入多个项目。回忆上一节,我们参数化的时候只能传入传入1个字符串或者是其他的数据对象,parametrize每次多个参数,更加灵活。
例子
import pytest
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
("6*9", 42),
])
def test_eval(test_input, expected):
assert eval(test_input) == expected
test_eval方法中传入了2个参数,就如同@pytest.mark.parametrize装饰器中定义的那样,因此简单理解,我们可以把parametrize装饰器想象成是数据表格,有表头(test_input,expected)以及具体的数据。
运行结果
$ pytest
======= test session starts ========
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items
test_expectation.py ..F
======= FAILURES ========
_______ test_eval[6*9-42] ________
test_input = '6*9', expected = 42
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
("6*9", 42),
])
def test_eval(test_input, expected):
> assert eval(test_input) == expected
E AssertionError: assert 54 == 42
E + where 54 = eval('6*9')
test_expectation.py:8: AssertionError
======= 1 failed, 2 passed in 0.12 seconds ========
pytest.6.Parametrize Fixture的更多相关文章
- Pytest系列(9) - 参数化@pytest.mark.parametrize
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 pytest允许在多个级别启 ...
- 5.@pytest.mark.parametrize()数据驱动
简介: pytest.mark.parametrize 是 pytest 的内置装饰器,它允许你在 function 或者 class 上定义多组参数和 fixture 来实现数据驱动. @pytes ...
- pytest进阶之fixture
前言 学pytest就不得不说fixture,fixture是pytest的精髓所在,就像unittest中的setup和teardown一样,如果不学fixture那么使用pytest和使用unit ...
- pytest自动化6:pytest.mark.parametrize装饰器--测试用例参数化
前言:pytest.mark.parametrize装饰器可以实现测试用例参数化. parametrizing 1. 下面是一个简单是实例,检查一定的输入和期望输出测试功能的典型例子 2. 标记单 ...
- pytest.10.使用fixture参数化测试预期结果
From: http://www.testclass.net/pytest/test_api_with_expected_result/ 背景 接上一节v2ex网站的查看论坛节点信息的api. 我们在 ...
- pytest框架之fixture前置和后置
一.conftest.py 定义公共的fixture,多个测试类中都可以调用 pytest提供了conftest.py文件,可以将fixture定义在此文件中 运行测试用例时,不需要去导入这个文件,会 ...
- Pytest【定制fixture】
在pytest中的fixture是在测试函数运行前后,由pytest执行的外壳函数,fixture中的代码可以定制,满足多变的测试需求:包括定义传入测试中的数据集.配置测试前系统的初始化状态.为批量测 ...
- pytest.mark.parametrize()参数化应用二,读取json文件
class TestEnorll(): def get_data(self): """ 读取json文件 :return: """ data ...
- pytest.mark.parametrize()参数化的应用一
from page.LoginPage import Loginpage import os, sys, pytest base_dir = os.path.dirname(os.path.dirna ...
随机推荐
- Java栈的简单实现
* 数据结构与算法Java实现 栈 * * @author 小明 * */ public class MyStack { private Node top;// 头指针 int size;// 长度 ...
- Vim 文件coding gbk格式
只需在 ~/.vimrc设置一致即可.文件编辑可正常显示中文,cat,不能正常显示,显示乱码,详情参考上篇. set fileencodings=utf-8,ucs-bom,gb18030,gbk,g ...
- php-fpm高并发配置[1000+]
Dell R430 2个物理CPU,每个CPU有6个内核: www.conf: pm = dynamic pm.max_children = 120 pm.start_servers = 8 pm.m ...
- SQL Server导入导出表及备份恢复
1. 导出: 2. 导入
- C++ 的简单输出输入 HDU 1089~1096
A+B for Input-Output Practice (I) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- CentOS右键菜单添加新增文件命令
进入模板文件夹, 增加空白文件即可. cd /home/tom/Templatesvi text01.txt //新增一个名为text01的文本文件. :wq //保存退出. 另外可以用LibreOf ...
- Damped Track 阻尼跟随
Damped Track 阻尼跟随 https://www.youtube.com/watch?v=pd1od5WPCUw 2个网格及对应的2个空对象Z轴方向网格:{O.up}; 上方园孔把手中间放空 ...
- MySql中的一些小坑
1. mysql启动时,若使用mysqld_safe的方式启动服务,需要使用mysqladmin shutdown的方式来停止服务. 若使用mysqld shutdown的方式停止服务,有可能会出现如 ...
- 【spring源码分析】BeanDefinitionRegistryPostProcessor解析
一.自定义BeanDefinitionRegistryPostProcessor BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProces ...
- 【mysql】创建索引
一.联合唯一索引 项目中需要用到联合唯一索引: 例如:有以下需求:每个人每一天只有可能产生一条记录:处了程序约定之外,数据库本身也可以设定: 例如:t_aa 表中有aa,bb两个字段,如果不希望有2条 ...