zoukankan      html  css  js  c++  java
  • pytest fixture执行顺序

    module和function的调用顺序:

    import pytest
    
    @pytest.fixture(scope="module", params=["mod1", "mod2"])
    def modarg(request):
        param = request.param
        print ("  SETUP modarg %s" % param)
        yield param
        print ("  TEARDOWN modarg %s" % param)
    
    @pytest.fixture(scope="function", params=[1,2])
    def otherarg(request):
        param = request.param
        print ("  SETUP otherarg %s" % param)
        yield param
        print ("  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:Codep2>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:python27python.exe
    cachedir: .pytest_cache
    rootdir: D:Codep2, 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 ===========================

  • 相关阅读:
    【题解】P1999 高维正方体
    【题解】 P1850 [NOIP2016 提高组] 换教室(又是一道debug的DP,debug经验++)
    【题解】P1439 【模板】最长公共子序列
    【笔记】还是发上来作为学习过的记录吧,凌乱,勿进
    为什么我不会做数位DP
    【题解】HUD3652 B-number && 数位DP学习笔记
    【题解】LIS(longest increasing subsequence)最长上升子序列
    lingo重点部分快速上手
    koa2转移json文件地址
    Koa2创建项目
  • 原文地址:https://www.cnblogs.com/tlmn2008/p/9590580.html
Copyright © 2011-2022 走看看