module和function的调用顺序:

import pytest@pytest.fixture(scope="module", params=["mod1", "mod2"])
def modarg(request):param = request.paramprint ("  SETUP modarg %s" % param)yield paramprint ("  TEARDOWN modarg %s" % param)@pytest.fixture(scope="function", params=[1,2])
def otherarg(request):param = request.paramprint ("  SETUP otherarg %s" % param)yield paramprint ("  TEARDOWN otherarg %s" % param)def test_0(otherarg):print ("  RUN test0 with otherarg %s" % otherarg)def test_1(modarg):print ("  RUN test1 with modarg %s" % modarg)def test_2(otherarg, modarg):print ("  RUN test2 with otherarg %s and modarg %s" % (otherarg, modarg))

结果:

D:\Code\p2>py.test test_module.py -v -s
============================= test session starts =============================
platform win32 -- Python 2.7.15, pytest-3.6.3, py-1.5.4, pluggy-0.6.0 -- c:\python27\python.exe
cachedir: .pytest_cache
rootdir: D:\Code\p2, inifile:
plugins: allure-adaptor-1.7.10
collected 8 items

test_module.py::test_0[1]

SETUP otherarg 1
RUN test0 with otherarg 1
PASSED TEARDOWN otherarg 1

test_module.py::test_0[2]

SETUP otherarg 2
RUN test0 with otherarg 2
PASSED TEARDOWN otherarg 2

test_module.py::test_1[mod1]

SETUP modarg mod1
RUN test1 with modarg mod1
PASSED

test_module.py::test_2[mod1-1]

SETUP otherarg 1
RUN test2 with otherarg 1 and modarg mod1
PASSED TEARDOWN otherarg 1

test_module.py::test_2[mod1-2]

SETUP otherarg 2
RUN test2 with otherarg 2 and modarg mod1
PASSED TEARDOWN otherarg 2

test_module.py::test_1[mod2]

TEARDOWN modarg mod1

SETUP modarg mod2
RUN test1 with modarg mod2
PASSED
test_module.py::test_2[mod2-1]

SETUP otherarg 1
RUN test2 with otherarg 1 and modarg mod2
PASSED TEARDOWN otherarg 1

test_module.py::test_2[mod2-2]

SETUP otherarg 2
RUN test2 with otherarg 2 and modarg mod2
PASSED TEARDOWN otherarg 2
TEARDOWN modarg mod2

========================== 8 passed in 0.12 seconds ===========================

转载于:https://www.cnblogs.com/tlmn2008/p/9590580.html

pytest fixture执行顺序相关推荐

  1. Pytest Hooks方法之pytest_collection_modifyitems改变测试用例执行顺序

    pytest默认执行用例顺序是根据项目下文件名称按ascii码去收集运行的,文件里的用例是从上往下按顺序执行的. pytest_collection_modifyitems 这个函数顾名思义就是收集测 ...

  2. Pytest-ordering自定义用例执行顺序

    我们一般在做自动化测试时,用例设计之间应该是可以相互独立执行的,没有一定的前后依赖关系的,如果我们真的有前后依赖,想指定用例的先后顺序,可以用到pytest-ordering插件解决这个问题 1.安装 ...

  3. 【pytest】Hook 方法之 pytest_collection_modifyitems:修改测试用例执行顺序

    pytest_collection_modifyitems 是在用例收集完毕之后被调用,可以用来调整测试用例执行顺序: 它有三个参数,分别是: session:会话对象: config:配置对象: i ...

  4. Python Pytest调用fixture之@pytest.mark.usefixtures()、叠加usefixtures、@pytest.fixture(autouse=True)用法详解

    usefixtures与传fixture区别  如果fixture有返回值,那么usefixture就无法获取到返回值,这个是装饰器usefixture与用例直接传fixture参数的区别. 当fix ...

  5. 【pytest】(二) pytest中的fixture (1) : fixture和fixture API —@pytest.fixture()的简单说明

    目录 1. fixture介绍 1.1 什么是fixture 1.2 与xUnit风格的setup和teardown的对比 1.3 fixture运行报错后,pytest的处理方式 2.fixture ...

  6. pytest框架_@pytest.fixture()

    pytest的几大函数介绍: @pytest.yield_fixture() @pytest.mark.xfail() @pytest.mark.skipif (1)@pytest.fixture() ...

  7. Pytest Fixture详解

    前言 在做自动化的过程中,编写用例时候需要用到用例的前置和用例的后置,其中pytest中有setup_class和teardown_class可以帮助我们完成这些,但是不够完善而且灵活性不够强.举个简 ...

  8. Pytest.fixture

    一.Pytest前置setup后置teardown在用例中的运行级别 1. 模块级 setup_module/teardown_module 这是全局的,在模块始末 def setup_module( ...

  9. Pytest fixture及conftest详解

    前言 fixture是在测试函数运行前后,由pytest执行的外壳函数.fixture中的代码可以定制,满足多变的测试需求,包括定义传入测试中的数据集.配置测试前系统的初始状态.为批量测试提供数据源等 ...

最新文章

  1. 没看完这11 条,别说你精通 Python 装饰器
  2. python函数作用域包括局部变量和参数_python函数变量的作用域声明(全局变量和局部变量)...
  3. Win11如何清理D盘垃圾
  4. STM32 SPI NSS 作用
  5. c++ n次方函数_高一数学必修一函数知识点总结
  6. Java基础学习总结(159)——JDK15 正式发布了!新增14个新特性
  7. 机器学习基础-线性代数学习
  8. mysql为什么用B 树做索引_mysql为什么用b+树做索引
  9. Java编程:排序算法
  10. zotero文献管理工具的下载安装
  11. 最新Python使用键鼠模拟,DNF拍卖行
  12. 微信公众号被动回复消息 Java实现
  13. 计算机6005是开机时间,怎么查电脑的开机,和关机时间·,同学们
  14. 联想计算机处理数据形态,联想 计算机基础知识.ppt
  15. UDP传输图片(分包)
  16. iOS 玩不转的GCD第0课时
  17. Consumer cannot be configured for auto commit for ackMode MANUAL_IMMEDIATE
  18. eclipse启动慢?试试如下操作
  19. k歌打分原理php,全民K歌修音教程:想要获得SSS评分其实很简单
  20. qq联系我们代码-qq在线客服代码

热门文章

  1. 去云南品味彝族的砣砣肉
  2. 关于《设计模式》这本书(三)——Proxy模式
  3. mysql字段获取当前日期格式_mysql数据库,获取当前日期及格式化
  4. 【消息中间件】RabbitMQ 高级特性与应用问题
  5. 使用uglify不能压缩的一些js语法(持续发现中)
  6. 基于ASP.Net Core开发的一套通用后台框架
  7. 洛谷 P3128 [USACO15DEC]最大流Max Flow
  8. noip2017考前基础复习——数论数学
  9. idea刷新项目、清除项目缓存
  10. Python的可视化包 – Matplotlib 2D图表(点图和线图,.柱状或饼状类型的图),3D图表(曲面图,散点图和柱状图)...