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

    > show status like 'Innodb_buffer_pool_read_%'; +---------------------------------------+-------- ...

  2. Linux 内存缓存占用过大,Centos7设置定时清除buff/cache的脚本

    Linux系统buff/cache 中缓存数据占用内存过高,定时清理buff/cache ,释放系统内存 root权限创建脚本文件: touch cleanCache.sh && vi ...

  3. MySQL数据库基本使用

    一 .数据库概述 数据库就是以一定格式进行组织的数据的集合.通俗来看数据库就是用户计算机上 一些具有特殊格式的数据文件的集合. 数据库也可以理解为表格,大家都知道表格都是由表名.表头.数据等几部分组成 ...

  4. python中常见的错误

    python中常见的错误   1.IndentationError: unindent does not match any outer indentation leve 众所周知,Python语法要 ...

  5. PyCharm软件代码配色和字体设置

    配置效果图: 1.字体设置: 2.tab键设置: 3.代码颜色配置: 注释颜色为: 类名称: 函数: 关键字: 关键字参数: 函数参数: 字符串:

  6. 树hash

    判断树的同构,采用树hash的方式. 树hash定义在有根树上.判断无根树同构的时候,可以比较重心为根的hash值或者比较每个点为根的hash值. h[x]表示x为根的子树的hash,g[x]表示x为 ...

  7. #socket #socketserver

    #通过socket 实现简单的ssh#服务端 #服务端 import os import socket server = socket.socket() #server.bind(('0.0.0.0' ...

  8. poweroj1745: 餐巾计划问题

    传送门 最小费用最大流. 每天拆成两个点,i表示用完的餐巾,i+n表示干净的餐巾. s向i连容量为ri费用为0的边,表示每天用脏的ri条餐巾. i+n向t连容量为ri费用为0的边,表示每天需要用ri条 ...

  9. SSM10-Redis持久化和集群的搭建

    1.1. Redis集群的搭建 Redis集群中至少应该有三个节点.要保证集群的高可用,需要每个节点有一个备份机. Redis集群至少需要6台服务器. 搭建伪分布式.可以使用一台虚拟机运行6个redi ...

  10. ios那些事之如何在ios5上运行gdb

    为啥要在ios上运行gdb? 这个问题见仁见智喽.对于搞开发的同学们来所, 有了gdb更方便跟踪分析别人的程序,取长补短:)这里不是教大家crack:) 运行环境: Mac OS 10.7.4 Xco ...