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 ...
随机推荐
- 排列组合lucas模板
//codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元) #include <bits/stdc++.h> using nam ...
- 嘴巴题8 BZOJ2318: Spoj4060 game with probability Problem
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 555 Solved: 273 [Submit][Status][Discuss] Description ...
- 数据库顶会VLDB论文解读:阿里数据库智能参数优化的创新与实践
前言 一年一度的数据库领域顶级会议VLDB 2019于美国当地时间8月26日-8月30日在洛杉矶召开.在本届大会上,阿里云数据库产品团队多篇论文入选Research Track和Industrial ...
- Django项目:CRM(客户关系管理系统)--66--56PerfectCRM实现CRM客户报名缴费链接
# kingadmin.py # ————————04PerfectCRM实现King_admin注册功能———————— from crm import models #print("ki ...
- Extjs4 的一些语法 持续更新中
一.给GridPanel增加成两行toolbar tbar: { xtype: 'container', layout: 'anchor', defaults: {anchor: '0'}, defa ...
- ubuntu下编译安装poco
系统环境: ubuntu版本:Linux jfcai-VirtualBox 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 ...
- non-identifying and identifying
An identifying relationship means that the child table cannot be uniquely identified without the par ...
- log4j 配置文件参数说明
log4j 框架配置文件常用参数说明 %d 时间(-- ::,) %-5p 日志级别(INFO/DEBUG) %10c 包名(com.xxx.xxx.business.logging) %M 执行的方 ...
- Leetcode434.Number of Segments in a String字符串中的单词数
统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符. 请注意,你可以假定字符串里不包括任何不可打印的字符. 示例: 输入: "Hello, my name is John" ...
- git cherry命令来比较两个分支的不同
git cherry 命令使用 1. 两个参数的情况 git cherry -v origin/master asa 比较本地的asa分支和远程master的差别 git cherry -v mast ...