我有一个conftest.py和一个插件,都用不同的实现定义了相同的灯具:
import pytest
@pytest.fixture
def f():
yield 1
import pytest
@pytest.fixture
def f():
yield 2
[安装插件时,conftest仍会覆盖该插件,因此测试文件将仅显示conftest固定装置,即
def test(f):
assert f == 1 # True
我希望能够做这样的事情:
我设法成功了一半:
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...
我看到的最简单的方法是尝试获取插件的固定值。如果灯具查找失败,则没有插件定义它,您可以做自己的事。示例: