【发布时间】:2019-11-22 08:56:23
【问题描述】:
Sample_test.py
@pytest.mark.parametrize(argnames="key",argvalues=ExcelUtils.getinputrows(__name__),scope="session")
def test_execute():
#Do something
conftest.py
@pytest.fixture(name='setup',autouse=True,scope="session")
def setup_test(pytestconfig):
dict['environment']="QA"
如上面的代码所示,我需要在 test_execute 方法之前运行 setup 夹具,因为 getinputrows 方法需要环境来读取工作表。不幸的是,参数化夹具在 setup_test 之前执行。有什么办法可以做到吗?
【问题讨论】:
-
parametrize不是固定装置,而是装饰器。装饰器在模块导入时进行评估,其中没有功能(包括固定装置)有机会执行。
标签: python pytest pytest-django