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的更多相关文章

  1. 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 ...

  2. pytest框架之mark标签

    对测试用例打标签,在运行测试用例的时候,可根据标签名来过滤要运行的用例. 一.注册标签名 1.创建pytest.ini文件,在文件中按如下方式添加标签名: [pytest] markers = smo ...

  3. 【pytest系列】- mark标记功能详细介绍

    如果想从头学起pytest,可以去看看这个系列的文章! https://www.cnblogs.com/miki-peng/category/1960108.html mark标记 ​ 在实际工作中, ...

  4. python+pytest接口自动化(11)-测试函数、测试类/测试方法的封装

    前言 在python+pytest 接口自动化系列中,我们之前的文章基本都没有将代码进行封装,但实际编写自动化测试脚本中,我们都需要将测试代码进行封装,才能被测试框架识别执行. 例如单个接口的请求代码 ...

  5. Python 装饰器装饰类中的方法

    title: Python 装饰器装饰类中的方法 comments: true date: 2017-04-17 20:44:31 tags: ['Python', 'Decorate'] categ ...

  6. python装饰器的4种类型:函数装饰函数、函数装饰类、类装饰函数、类装饰类

    一:函数装饰函数 def wrapFun(func): def inner(a, b): print('function name:', func.__name__) r = func(a, b) r ...

  7. Python入门之python装饰器的4种类型:函数装饰函数、函数装饰类、类装饰函数、类装饰类

    一:函数装饰函数 def wrapFun(func): def inner(a, b): print('function name:', func.__name__) r = func(a, b) r ...

  8. java IO流的继承体系和装饰类应用

    java IO流的设计是基于装饰者模式&适配模式,面对IO流庞大的包装类体系,核心是要抓住其功能所对应的装饰类. 装饰模式又名包装(Wrapper)模式.装饰模式以对客户端透明的方式扩展对象的 ...

  9. Python 使用装饰器装饰类

    1.装饰器装饰函数 了解过或学过装饰器的同学都知道,Python 中的装饰器是可以装饰函数的,如: # 定义一个装饰器 def decorator(func): def inner(*args,**k ...

随机推荐

  1. [转]【全面解禁!真正的Expression Blend实战开发技巧】第六章 认识ListBox

    反反复复考虑后,准备把这一章的切入点瞄准ListBox.并用了一个看起来有点别扭的标题“认识ListBox",许多人看到这里就不爱看了,即使是大学里用winform的学生也会说ListBox ...

  2. Ajax 导出Excel 方式

    1.使用iframe 加载 使用get方式 <iframe id="comdownshow" height="0" width="0" ...

  3. 19-10-23-K-Aft

    没改完题就过来沽博客是不是有点不好…… ZJ一下: 好好好题. T1数组大小…… $$10^7 \rightarrow 60$$ 事实上…… $$7 \times 10^7 \rightarrow 0 ...

  4. 使用内部Servlet转发JSP后页面的JS,CSS等资源引入问题的解决

    转载自:https://blog.csdn.net/weixin_44353336/article/details/90677792 问题原因 我们在进行web项目开发过程中,经常会在web页面引入一 ...

  5. PAT甲级——A1021 Deepest Root

    A graph which is connected and acyclic can be considered a tree. The height of the tree depends on t ...

  6. Http请求中的Content-Type

    转载至:https://segmentfault.com/a/1190000013056786?utm_source=tag-newest 一 前言 ----现在搞前端的不学好http有关的知识已经不 ...

  7. VS2015使用Nuget安装OpenCV3.X以及Python3安装OpenCV3.X

    VS2015已经自带Nuget安装工具了,所以,新建一个项目,点击管理Nuget包 搜索OpenCV3 注意,目前只有这个版本支持VS2015,也就是平台工具集可以为vs140,其他的都会报错,报错我 ...

  8. 基于RBAC权限管理的后台管理系统

    在摸爬滚打中渐渐理解了RBAC权限管理是个什么玩意. RBAC的基本概念: **RBAC认为权限授权实际上是Who.What.How的问题.在RBAC模型中,who.what.how构成了访问权限三元 ...

  9. 读书笔记--Head First PMP目录

    1.引言 2.阻止.约束和项目 3.过程框架 4.项目整合管理 5.范围管理 6.时间管理 7.成本管理 8.质量管理 9.人力资源管理 10.沟通管理 11.项目风险管理 12.采购管理 13.职业 ...

  10. redis 原生操作 & python操作redis

    一.基本介绍 1.简介 Redis是由意大利人Salvatore Sanfilippo(网名:antirez)开发的一款内存高速缓存数据库.Redis全称为:Remote Dictionary Ser ...