Python pytest获取运行时函数测试变量
我正在使用插件repeat,需要在运行时提取当前测试(用于记录器)。我假设我将访问:dummy.py::test_dummy[1-4]Python pytest获取运行时函数测试变量,python,pytest,Python,Pytest,我正在使用插件repeat,需要在运行时提取当前测试(用于记录器)。我假设我将访问: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<<
@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
@pytest.fixture(scope=“session”)
def初始_设置():
打印(f'\n\n>')
计数器不工作=0
产量计数器不工作
打印(“\n>”)
@pytest.mark.repeat(int(os.getenv(“repeat”,“4”))
def测试假人(初始设置):
#备选案文1
计数器不工作=初始设置
计数器不工作=+1
打印(f'\n用于记录器…,测试号:{counter\u not\u working}???)
#备选案文2
计数器_从_pytest获取_=0#???
打印(f'用于记录器…,测试号:{counter_get_from_pytest}??)
通过
===========================================测试会话开始==============================
平台linux——Python 3.7.5、pytest-4.4.1、py-1.8.0、pluggy-0.9.0——xxx/xxx
cachedir:.pytest\u缓存
rootdir:/xxx/,ini文件:pytest.ini
插件:重复-0.8.0
收集。。。收集4项
dummy.py::test_dummy[1-4]
>
通过[25%]
用于记录器…,测试编号:1???
用于记录器…,测试编号:0
dummy.py::测试_dummy[2-4]通过[50%]
用于记录器…,测试编号:1???
用于记录器…,测试编号:0
假人。py::试验假人[3-4]通过[75%]
用于记录器…,测试编号:1???
用于记录器…,测试编号:0
dummy.py::测试_dummy[4-4]通过[100%]
用于记录器…,测试编号:1???
用于记录器…,测试编号:0
>
====================================================4秒在0.02秒内通过===========================
进程结束,退出代码为0我发现自己:
def测试假人(初始设置,请求):
无测试数=str(请求.节点)
打印(类型(无测试)