diff --git a/py/test/funcargs.py b/py/test/funcargs.py index 22ba09807..f1c5d2708 100644 --- a/py/test/funcargs.py +++ b/py/test/funcargs.py @@ -33,9 +33,11 @@ class Metafunc: self._calls = [] self._ids = py.builtin.set() - def addcall(self, funcargs=None, id=None, param=_notexists): + def addcall(self, funcargs=None, id=_notexists, param=_notexists): assert funcargs is None or isinstance(funcargs, dict) if id is None: + raise ValueError("id=None not allowed") + if id is _notexists: id = len(self._calls) id = str(id) if id in self._ids: diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 620d39a7d..16fd5d5d3 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -313,6 +313,7 @@ class Function(FunctionMixin, py.test.collect.Item): """ a Function Item is responsible for setting up and executing a Python callable test object. """ + _genid = None def __init__(self, name, parent=None, config=None, args=(), callspec=None, callobj=_dummy): super(Function, self).__init__(name, parent, config=config) @@ -320,9 +321,13 @@ class Function(FunctionMixin, py.test.collect.Item): if args: assert not callspec, "yielded functions (deprecated) cannot have funcargs" else: - self.funcargs = callspec and callspec.funcargs or {} - if hasattr(callspec, "param"): - self._requestparam = callspec.param + if callspec is not None: + self.funcargs = callspec.funcargs or {} + self._genid = callspec.id + if hasattr(callspec, "param"): + self._requestparam = callspec.param + else: + self.funcargs = {} if callobj is not _dummy: self._obj = callobj @@ -351,8 +356,8 @@ class Function(FunctionMixin, py.test.collect.Item): self._args == other._args and self.parent == other.parent and self.obj == other.obj and - getattr(self, '_requestparam', None) == - getattr(other, '_requestparam', None) + getattr(self, '_genid', None) == + getattr(other, '_genid', None) ) except AttributeError: pass diff --git a/py/test/testing/test_funcargs.py b/py/test/testing/test_funcargs.py index bb7e832ae..b34a2e662 100644 --- a/py/test/testing/test_funcargs.py +++ b/py/test/testing/test_funcargs.py @@ -298,6 +298,8 @@ class TestMetafunc: def test_addcall_id(self): def func(arg1): pass metafunc = funcargs.Metafunc(func) + py.test.raises(ValueError, "metafunc.addcall(id=None)") + metafunc.addcall(id=1) py.test.raises(ValueError, "metafunc.addcall(id=1)") py.test.raises(ValueError, "metafunc.addcall(id='1')") @@ -338,6 +340,7 @@ class TestGenfuncFunctional: metafunc.addcall(param=metafunc) def pytest_funcarg__metafunc(request): + assert request._pyfuncitem._genid == "0" return request.param def test_function(metafunc): diff --git a/py/test/testing/test_pycollect.py b/py/test/testing/test_pycollect.py index 10efc9e55..402ace27a 100644 --- a/py/test/testing/test_pycollect.py +++ b/py/test/testing/test_pycollect.py @@ -242,25 +242,16 @@ class TestFunction: assert f1 == f1_b assert not f1 != f1_b + def test_function_equality_with_callspec(self, tmpdir): + config = py.test.config._reparse([tmpdir]) class callspec1: param = 1 funcargs = {} + id = "hello" class callspec2: - param = 2 - funcargs = {} - f5 = py.test.collect.Function(name="name", config=config, - callspec=callspec1, callobj=isinstance) - f5b = py.test.collect.Function(name="name", config=config, - callspec=callspec2, callobj=isinstance) - assert f5 != f5b - assert not (f5 == f5b) - - class callspec1: param = 1 funcargs = {} - class callspec2: - param = 2 - funcargs = {} + id = "world" f5 = py.test.collect.Function(name="name", config=config, callspec=callspec1, callobj=isinstance) f5b = py.test.collect.Function(name="name", config=config,