栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytest setup与用例之间传参

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pytest setup与用例之间传参

pytest前置钩子(setup)与用例之间互相传参

import pytest
import time

@pytest.fixture()
def setup(request):
    begin_time = time.time()
    print('param from case: %s' % request.param)
    return begin_time

@pytest.mark.parametrize('setup',[1,5], indirect=True)  #indirect 把setup当作函数执行
@pytest.mark.parametrize('a,b',
                         [(1,5),(3,4)])
def test_param(setup,a,b):
    begin_time = setup
    print('begin_time is: ', begin_time)
    print('param_a', a)
    print('param_b', b)

执行结果:

Launching pytest with arguments test1.py::test_param --no-header --no-summary -q in D:pythontest

============================= test session starts =============================
collecting ... collected 4 items

test1.py::test_param[1-5-1] param from case: 1
PASSED                                       [ 25%]begin_time is:  1659103133.1927586
param_a 1
param_b 5

test1.py::test_param[1-5-5] param from case: 5
PASSED                                       [ 50%]begin_time is:  1659103133.1967208
param_a 1
param_b 5

test1.py::test_param[3-4-1] param from case: 1
PASSED                                       [ 75%]begin_time is:  1659103133.2007089
param_a 3
param_b 4

test1.py::test_param[3-4-5] param from case: 5
PASSED                                       [100%]begin_time is:  1659103133.2037005
param_a 3
param_b 4


============================== 4 passed in 0.02s ==============================

Process finished with exit code 0
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1030496.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号