【发布时间】: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 结束
【问题讨论】: