[py-dev] py.test: customizing collector
Ian Bicking
ianb at colorstudy.com
Sun Nov 21 09:26:02 CET 2004
I got a custom collector working okay; this checks for a function
attribute "params", which is a list of tuples, each of which is an
argument. I did it like this:
from py.test.collect import PyCollector
class ParamCollector(PyCollector):
def collect_function(self, extpy):
if not extpy.check(func=1, basestarts='test_'):
return
func = extpy.resolve()
if hasattr(func, 'params'):
params = func.params
for param in params:
yield self.Item(extpy, *param)
else:
yield self.Item(extpy)
The problem is that all the tests have the same name, at least as
displayed. I notice that item.extpy is used as the displayed name for
the test; at least some other function should be used
(py.test.report.text.summary:192) so that it's easier to override. But
I guess it should also fit into --session, and I don't know what that
uses for its test ID...?
It might be nice if this parameterization was built into the standard
collector in some way, as it's a very common case. I'm not sure if it's
best as an attribute, a similarly-named object (e.g., test_func and
test_func_params), or if there's other ideas.
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Pytest-dev
mailing list