From e79f4d298c8a47009975f13dbf4077b4c06b00ff Mon Sep 17 00:00:00 2001 From: Samuele Pedroni Date: Thu, 21 May 2009 19:08:33 +0200 Subject: [PATCH 1/2] minimal changes to expose fillfuncargs --HG-- branch : trunk --- py/__init__.py | 1 + py/test/funcargs.py | 2 +- py/test/testing/test_funcargs.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/py/__init__.py b/py/__init__.py index 5ff8de317..555a3f014 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -79,6 +79,7 @@ initpkg(__name__, 'test.fail' : ('./test/outcome.py', 'fail'), 'test.exit' : ('./test/outcome.py', 'exit'), 'test.pdb' : ('./test/custompdb.py', 'set_trace'), + 'test.fillfuncargs' : ('./test/funcargs.py', 'fillfuncargs'), # configuration/initialization related test api 'test.config' : ('./test/config.py', 'config_per_process'), diff --git a/py/test/funcargs.py b/py/test/funcargs.py index 72d37265c..22ba09807 100644 --- a/py/test/funcargs.py +++ b/py/test/funcargs.py @@ -95,7 +95,7 @@ class FuncargRequest: def _fillfuncargs(self): argnames = getfuncargnames(self.function) if argnames: - assert not self._pyfuncitem._args, "yielded functions cannot have funcargs" + assert not getattr(self._pyfuncitem, '_args', None), "yielded functions cannot have funcargs" for argname in argnames: if argname not in self._pyfuncitem.funcargs: self._pyfuncitem.funcargs[argname] = self.getfuncargvalue(argname) diff --git a/py/test/testing/test_funcargs.py b/py/test/testing/test_funcargs.py index 566ade322..2c0446429 100644 --- a/py/test/testing/test_funcargs.py +++ b/py/test/testing/test_funcargs.py @@ -79,6 +79,17 @@ class TestFillFuncArgs: "*1 passed*" ]) + def test_fillfuncargs_exposed(self, testdir): + item = testdir.getitem("def test_func(some, other=42): pass") + class Provider: + def pytest_funcarg__some(self, request): + return request.function.__name__ + item.config.pluginmanager.register(Provider()) + if hasattr(item, '_args'): + del item._args + py.test.fillfuncargs(item) + assert len(item.funcargs) == 1 + class TestRequest: def test_request_attributes(self, testdir): item = testdir.getitem(""" From f50b39980cb934b670c5f5e288bc87cb3c7cde05 Mon Sep 17 00:00:00 2001 From: Samuele Pedroni Date: Thu, 21 May 2009 19:36:02 +0200 Subject: [PATCH 2/2] addresses issue15 expose fillfuncargs as py.test.collect._fillfuncargs instead for now --HG-- branch : trunk --- py/__init__.py | 2 +- py/test/testing/test_funcargs.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/py/__init__.py b/py/__init__.py index 555a3f014..0406b2023 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -79,7 +79,6 @@ initpkg(__name__, 'test.fail' : ('./test/outcome.py', 'fail'), 'test.exit' : ('./test/outcome.py', 'exit'), 'test.pdb' : ('./test/custompdb.py', 'set_trace'), - 'test.fillfuncargs' : ('./test/funcargs.py', 'fillfuncargs'), # configuration/initialization related test api 'test.config' : ('./test/config.py', 'config_per_process'), @@ -96,6 +95,7 @@ initpkg(__name__, 'test.collect.Instance' : ('./test/pycollect.py', 'Instance'), 'test.collect.Generator' : ('./test/pycollect.py', 'Generator'), 'test.collect.Function' : ('./test/pycollect.py', 'Function'), + 'test.collect._fillfuncargs' : ('./test/funcargs.py', 'fillfuncargs'), # thread related API (still in early design phase) '_thread.WorkerPool' : ('./thread/pool.py', 'WorkerPool'), diff --git a/py/test/testing/test_funcargs.py b/py/test/testing/test_funcargs.py index 2c0446429..bb7e832ae 100644 --- a/py/test/testing/test_funcargs.py +++ b/py/test/testing/test_funcargs.py @@ -87,7 +87,7 @@ class TestFillFuncArgs: item.config.pluginmanager.register(Provider()) if hasattr(item, '_args'): del item._args - py.test.fillfuncargs(item) + py.test.collect._fillfuncargs(item) assert len(item.funcargs) == 1 class TestRequest: