introduce a pytest_collect_metainfo hook

--HG--
branch : trunk
This commit is contained in:
Samuele Pedroni 2009-05-12 14:50:25 +02:00
parent 69214d053d
commit 4956e00a49
3 changed files with 23 additions and 0 deletions

View File

@ -53,6 +53,11 @@ class PluginHooks:
""" return custom item/collector for a python object in a module, or None. """ """ return custom item/collector for a python object in a module, or None. """
pytest_pycollect_obj.firstresult = True pytest_pycollect_obj.firstresult = True
def pytest_collect_metainfo(self, colitem):
""" return (fspath, lineno, name) for the colitem.
the information is used for result display and to sort tests
"""
def pytest_genfunc(self, funcspec): def pytest_genfunc(self, funcspec):
""" generate (multiple) parametrized calls to a test function.""" """ generate (multiple) parametrized calls to a test function."""

View File

@ -82,6 +82,9 @@ class PyobjMixin(object):
return self._fslineno return self._fslineno
def metainfo(self): def metainfo(self):
res = self.config.hook.pytest_collect_metainfo(colitem=self)
if res:
return res
fspath, lineno = self._getfslineno() fspath, lineno = self._getfslineno()
modpath = self.getmodpath() modpath = self.getmodpath()
return fspath, lineno, modpath return fspath, lineno, modpath

View File

@ -397,3 +397,18 @@ class TestMetaInfo:
def test_method(self): def test_method(self):
pass pass
""" """
def test_pytest_collect_metainfo(self, testdir):
wascalled = []
class Plugin:
def pytest_collect_metainfo(self, colitem):
wascalled.append(colitem)
item = testdir.getitem("def test_func(): pass")
item.config.pluginmanager.register(Plugin())
fspath, lineno, modpath = item.metainfo()
assert wascalled == [item]