日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pytest fixture执行顺序

發布時間:2025/5/22 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pytest fixture执行顺序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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执行顺序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。