diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index 7f057b3fb..ff015fb62 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -53,6 +53,11 @@ class PluginHooks: """ return custom item/collector for a python object in a module, or None. """ 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): """ generate (multiple) parametrized calls to a test function.""" diff --git a/py/test/pycollect.py b/py/test/pycollect.py index fe4f99861..a2f8d306f 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -82,6 +82,9 @@ class PyobjMixin(object): return self._fslineno def metainfo(self): + res = self.config.hook.pytest_collect_metainfo(colitem=self) + if res: + return res fspath, lineno = self._getfslineno() modpath = self.getmodpath() return fspath, lineno, modpath diff --git a/py/test/testing/test_pycollect.py b/py/test/testing/test_pycollect.py index 4a7d3e6e0..145a701cc 100644 --- a/py/test/testing/test_pycollect.py +++ b/py/test/testing/test_pycollect.py @@ -397,3 +397,18 @@ class TestMetaInfo: def test_method(self): 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] + +