pytest 用 @pytest.mark.usefixtures("fixtureName")装饰类,可以让执行每个case前,都执行一遍指定的fixture
conftest.py
- import pytest
- import uuid
- @pytest.fixture()
- def declass():
- print("declass:"+str(uuid.uuid4()))
- return "declass"
- test_forclass.py
- import pytest
- @pytest.mark.usefixtures("declass")
- class TestClass(object):
- def test_case1(self):
- print("test_case1:")
- assert 0==0
- def test_case2(self):
- print("test_case2:")
- assert 0 == 0
执行结果:
可以从结果中看到每个case执行前,都执行了declass这个fixture,且每次都是重新调用。 (这种使用方法,从官方给出的例子来看,应该用于数据清理或准备比较合适。)
还支持引用多个fixture
conftest.py
- import pytest
- import uuid
- @pytest.fixture()
- def declass():
- print("declass:"+str(uuid.uuid4()))
- return "declass"
- @pytest.fixture()
- def declass2():
- print("declass2:"+str(uuid.uuid4()))
- return "declass2"
- test_forclass.py
- @pytest.mark.usefixtures("declass","declass2")
- class TestClass(object):
- def test_case1(self):
- print("test_case1:")
- assert 0==0
- def test_case2(self):
- print("test_case2:")
- assert 0 == 0
执行结果:
pytest 用 @pytest.mark.usefixtures("fixtureName")装饰类,可以让执行每个case前,都执行一遍指定的fixture的更多相关文章
- pytest 用 @pytest.mark.usefixtures("fixtureName")或@pytest.fixture(scope="function", autouse=True)装饰,实现类似setup和TearDown的功能
conftest.py import pytest @pytest.fixture(scope="class") def class_auto(): print("&qu ...
- pytest框架之mark标签
对测试用例打标签,在运行测试用例的时候,可根据标签名来过滤要运行的用例. 一.注册标签名 1.创建pytest.ini文件,在文件中按如下方式添加标签名: [pytest] markers = smo ...
- 【pytest系列】- mark标记功能详细介绍
如果想从头学起pytest,可以去看看这个系列的文章! https://www.cnblogs.com/miki-peng/category/1960108.html mark标记 在实际工作中, ...
- python+pytest接口自动化(11)-测试函数、测试类/测试方法的封装
前言 在python+pytest 接口自动化系列中,我们之前的文章基本都没有将代码进行封装,但实际编写自动化测试脚本中,我们都需要将测试代码进行封装,才能被测试框架识别执行. 例如单个接口的请求代码 ...
- Python 装饰器装饰类中的方法
title: Python 装饰器装饰类中的方法 comments: true date: 2017-04-17 20:44:31 tags: ['Python', 'Decorate'] categ ...
- python装饰器的4种类型:函数装饰函数、函数装饰类、类装饰函数、类装饰类
一:函数装饰函数 def wrapFun(func): def inner(a, b): print('function name:', func.__name__) r = func(a, b) r ...
- Python入门之python装饰器的4种类型:函数装饰函数、函数装饰类、类装饰函数、类装饰类
一:函数装饰函数 def wrapFun(func): def inner(a, b): print('function name:', func.__name__) r = func(a, b) r ...
- java IO流的继承体系和装饰类应用
java IO流的设计是基于装饰者模式&适配模式,面对IO流庞大的包装类体系,核心是要抓住其功能所对应的装饰类. 装饰模式又名包装(Wrapper)模式.装饰模式以对客户端透明的方式扩展对象的 ...
- Python 使用装饰器装饰类
1.装饰器装饰函数 了解过或学过装饰器的同学都知道,Python 中的装饰器是可以装饰函数的,如: # 定义一个装饰器 def decorator(func): def inner(*args,**k ...
随机推荐
- Leetcode965. Univalued Binary Tree单值二叉树
如果二叉树每个节点都具有相同的值,那么该二叉树就是单值二叉树. 只有给定的树是单值二叉树时,才返回 true:否则返回 false. 示例 1: 输入:[1,1,1,1,1,null,1] 输出:tr ...
- 如何解决mysql服务器load高
.登录主机 # ssh hostname .确定是否是mysql导致 # top .查看是哪些sql正在慢查询 # mysql -h hostname -P port -u username # sh ...
- leetcode 238 & leetcode 152 & leetcode 228
lc238 Product of Array Except Self 遍历两次数组 用一个res[] 记录答案 1) 第一次,从左往右遍历 res[i] 记录0~i-1的乘积 2) 第二次,从右往左遍 ...
- 原子操作atomic
一.原子操作:即不可再细分的操作,最小的执行单位,在操作完之前都不会被任何事件中断. 整型原子操作:对int类型的操作变成原子操作. int i = 0; ...
- Ionic cordova-plugin-splashscreen
1.添加插件 cordova plugin add https://github.com/apache/cordova-plugin-splashscreen.git 2.设置启动画面 在根目录下面r ...
- anchor-free : CornerNet 和 CenterNet 简要笔记
CornerNethourglass network -> prediction module = corner pooling -> heatmaps + embedding + off ...
- 微信小程序——页面滑动事件
wxml: <view id="id" class = "ball" bindtap = "handletap" bindtouchs ...
- 20191005 - New Beginning
真·反思 Before 发现$T1$是约瑟夫,$T2$不清楚,$T3$是算法进阶上的$LCIS$ During得&失 做的不错的地方: 多少想了T1的优化(最后没打完). T3的暴力写得很快也 ...
- springcloud 与分布式系统(转载)
原地址:http://blog.csdn.net/neosmith/article/details/51919038 本文不是讲解如何使用spring Cloud的教程,而是探讨Spring Clou ...
- HDFS体系结构概述