我有一个conftest.py和一个插件,它们都用不同的实现定义了相同的fixture:
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...
我看到的最简单的方法是尝试获取插件fixture值。如果fixture查找失败,那么没有插件定义它,您可以自己做事情。例如:
相关问题 更多 >
编程相关推荐