【发布时间】:2020-05-27 11:25:30
【问题描述】:
我有一个 conftest.py 和一个插件,它们都定义了具有不同实现的相同夹具:
conftest.py
>import pytest
@pytest.fixture
def f():
yield 1
插件
import pytest
@pytest.fixture
def f():
yield 2
在安装插件时,conftest 仍然会覆盖插件,因此测试文件只会看到 conftest 夹具,即
test_.py
>def test(f):
assert f == 1 # True
我希望能够做这样的事情:
- 如果没有安装插件,继续
- 否则,来自 conftest 插件,产生插件夹具的值
我成功了一半:
conftest.py
>import pytest
@pytest.fixture
def f(pytestconfig):
if pytestconfig.pluginmanager.has_plugin(plugin_name):
# now what? I have get_plugin and import_plugin, but I'm not able to get the fixture from there...
【问题讨论】:
标签: python python-3.x pytest fixtures