鉴于以下模拟:
import pytest
class DummyFile(pytest.File):
def collect(self):
yield DummyItem(self, self)
class DummyItem(pytest.Item):
def __init__(self, pytest_file, parent):
super(DummyItem, self).__init__(pytest_file.name, parent)
self.pytest_file = pytest_file
def runtest(self):
...
def pytest_collect_file(self, parent, path):
if path.ext == ".rst":
return DummyFile(path, parent)
如何指出DummyFile
或DummyItem
实例需要特定的灯具?
如何从DummyItem
内的DummyFile
及其父DummyItem.runtest
获取这些灯具?
答案 0 :(得分:1)
很遗憾,截至2017年8月,还没有正式的API来访问pytest.Item
子类的灯具,请参阅此Github issue。该问题的海报有Github gist,显示您必须使用的内部API:
fm = self.session._fixturemanager
names_closure, arg2fixturedefs = fm.getfixtureclosure(names, self)
fixtureinfo = FuncFixtureInfo(names, names_closure, arg2fixturedefs)
self._fixtureinfo = fixtureinfo
self.funcargs = {}
self._request = fixtures.FixtureRequest(self)