【问题标题】:pytest get runtime function test variablepytest 获取运行时函数测试变量
【发布时间】:2020-01-23 15:28:21
【问题描述】:

我正在使用插件重复,需要在运行时提取当前测试(用于记录器)。我假设我将访问: dummy.py::test_dummy[1-4]

@pytest.fixture(scope="session")
def initial_setup():
    print(f'\n\n<<< setup >>>')
    counter_not_working = 0
    yield counter_not_working
    print('\n<<< teardown >>>')

@pytest.mark.repeat(int(os.getenv("repeat", "4")))
def test_dummy(initial_setup):

    # Alt.1
    counter_not_working = initial_setup
    counter_not_working = + 1
    print(f'\nTo be used for a logger..., test no: {counter_not_working}???')

    # Alt.2
    counter_get_from_pytest = 0  # ???
    print(f'To be used for a logger..., test no: {counter_get_from_pytest}???')
    pass

============================== 测试会话开始 =============== ================ 平台 linux -- Python 3.7.5、pytest-4.4.1、py-1.8.0、pluggy-0.9.0 -- xxx/xxx 缓存目录:.pytest_cache 根目录:/xxx/,inifile:pytest.ini 插件:重复-0.8.0 收集...收集了 4 件物品

dummy.py::test_dummy[1-4]

>> 通过 [ 25%] 用于记录器...,测试号:1??? 用于记录器...,测试号:0???

dummy.py::test_dummy[2-4] 通过 [50%] 用于记录器...,测试号:1??? 用于记录器...,测试号:0???

dummy.py::test_dummy[3-4] 通过 [ 75%] 用于记录器...,测试号:1??? 用于记录器...,测试号:0???

dummy.py::test_dummy[4-4] 通过 [100%] 用于记录器...,测试号:1??? 用于记录器...,测试号:0???

>>

============================ 4 在 0.02 秒内通过 =============== =============

进程以退出代码 0 结束

【问题讨论】:

    标签: python pytest


    【解决方案1】:

    我找到了我自己:

    def test_dummy(initial_setup, request): no_of_tests = str(request.node) 打印(类型(no_of_tests))

    【讨论】:

      猜你喜欢
      • 2017-05-09
      • 2018-08-28
      • 2018-01-25
      • 2020-12-06
      • 2018-06-01
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 2020-04-25
      相关资源
      最近更新 更多