pytest fixture中scope试验,包含function、module、class、session、package

上图是试验的目录结构
conftest.py:存放pytest fixture的文件
import uuid
import pytest @pytest.fixture(scope="module")
def test_module():
return "module"+str(uuid.uuid4()) @pytest.fixture(scope="class")
def test_class():
return "class"+str(uuid.uuid4()) @pytest.fixture(scope="function")
def test_function():
return "function"+str(uuid.uuid4()) @pytest.fixture(scope="session")
def test_session():
return "session"+str(uuid.uuid4()) @pytest.fixture(scope="package")
def test_package():
return "package"+str(uuid.uuid4())
test_class.py:类测试文件
class Test_for_pytest_scope(object):
def test_case1(self,test_module,test_class,test_function,test_session,test_package):
print("testcase/test_class.py-test_case1||" + test_function)
print("testcase/test_class.py-test_case1||"+test_module)
print("testcase/test_class.py-test_case1||"+test_class)
print("testcase/test_class.py-test_case1||" + test_session)
print("testcase/test_class.py-test_case1||" + test_package) def test_case2(self,test_module,test_class,test_function,test_session,test_package):
print("testcase/test_class.py-test_case2||" + test_function)
print("testcase/test_class.py-test_case2||"+test_module)
print("testcase/test_class.py-test_case2||"+test_class)
print("testcase/test_class.py-test_case2||" + test_session)
print("testcase/test_class.py-test_case2||" + test_package)
其它测试文件都是打印fixture的返回信息
下图是打印结果

结论:
package的试验结果和预期有些出入,其它的作用范围大小关系为 function<class<module<session
| function | 每个方法和函数执行前都会重新调用一些fixture,得到一个新的uuid |
| class | 一个文件(module)内,class内部方法共享数据,函数不共享数据 |
| module | 一个文件就是一个module,一个module内只执行一次fixture,且module内共享数据 |
| package | uuid都一致,和理解上有些出入,以为不同package会重新调用一次fixture |
| session |
一次执行都一致 |
补充:翻看官方文档,发现package还处于试验阶段。

pytest fixture中scope试验,包含function、module、class、session、package的更多相关文章
- 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:通过scope控制fixture的作用范围
一.fixture里面有个参数scope,通过scope可以控制fixture的作用范围,根据作用范围大小划分:session>module>class>function,具体作用范 ...
- jsp中iframe所包含的页面调用父页面的function方法
a.jsp中写了注册的Ext窗体loginWindow,也用iframe包含了另一个b.jsp,当在b.jsp中也有点击注册的链接,这时需要用到调用a.jsp中的loginWindow,因为如果你重新 ...
- abap function module中的异常处理
1: 定义一个有异常抛出的function module. (zfm_moudle6), 该函数中有符合exceptions中的异常,将会自动将exceptions中的异常抛出. FUNCTION ...
- 在function module 中向数据库插入数据
http://www.sapjx.com/abap-function-module.html 1: 应该在function module 中向数据库插入数据
- Pytest fixture及conftest详解
前言 fixture是在测试函数运行前后,由pytest执行的外壳函数.fixture中的代码可以定制,满足多变的测试需求,包括定义传入测试中的数据集.配置测试前系统的初始状态.为批量测试提供数据源等 ...
- pytest fixture 利用 params参数实现用例集合
@pytest.fixture有一个params参数,接受一个列表,列表中每个数据都可以作为用例的输入.也就说有多少数据,就会形成多少用例.如下面例子,就形成3条用例 test_parametrizi ...
- Pytest测试框架(三):pytest fixture 用法
xUnit style 结构的 fixture用于初始化测试函数, pytest fixture是对传统的 xUnit 架构的setup/teardown功能的改进.pytest fixture为测试 ...
- pytest--fixture基本使用(主要用来进行测试环境的初始化和清理,fixture中的params参数还可以用来进行参数化)
fixture fixture修饰器来标记固定的工厂函数,在其他函数,模块,类或整个工程调用它时会被激活并优先执行,通常会被用于完成预置处理和重复操作. 方法: fixture(scope=" ...
随机推荐
- [转]C#中用NamedPipe进程间通信
转自:http://blog.csdn.net/jinjazz/archive/2009/02/03/3861143.aspx 本文只是一个测试例子,核心代码是kernel32.dll中的一组wind ...
- 关于mysql8授权的问题,mysql萌新小白采坑记录
记录本人第一次使用mysql时踩的坑,因为我从官网下载最新的版本8.0.15msi版本的,直接下一步下一步安装完成之后,本地访问正常,然后服务器安装访问也正常.然后本地连接服务器上的mysql时报错. ...
- jaxFileUpload插件异步上传图片
第一步:引入jquery文件和jaxFileUpload文件 文件位置:https://pan.baidu.com/s/1jHEyIyy 第二步,前端: <div class="for ...
- scrollLeft/scrollTop/scrollHeight
scrollHeight : It includes the element's padding, but not its border or margin.This property will ...
- [jeecms]获取父栏目下的子栏目名称
[@cms_channel_list parentId='父栏目id'] [#list tag_list as c] <a href="${c.url}">${c.na ...
- 2018-8-14-Resharper-如何把类里的类移动到其他文件
title author date CreateTime categories Resharper 如何把类里的类移动到其他文件 lindexi 2018-08-14 17:34:39 +0800 2 ...
- Luogu P2678 跳石头(二分)
P2678 跳石头 题意 题目背景 一年一度的"跳石头"比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起 ...
- LA4254 Processor
题意:有n个任务,每个任务有三个参数ri,di和wi,表示必须在时刻[ri,di]之内执行,工作量为wi.处理器执行速度可以变化,当执行速度为s时,工作量为wi.处理器的速度可以变化,当执行速度为 ...
- 移动端页面输入法挡住input输入框的解决方法
1,宽高用了百分比或者vw/vh布局的,input输入框的最外层父容器的可用JS动态设置为当前窗口的宽高(防止输入法的弹出令页面变形) 2,最外层父容器用了fixed定位的,不要用top:0;要用bo ...
- 玩转webpack之webpack的entry output
webpack的入口配置项表示要配置的文件就是开发环境或者生产环境 浏览器本身不能认识的一些东西必须经过webpack的编译才能认识,但是要去写的时候我们经常用到预编译什么的比如scss比如jsx甚至 ...