From 5e03bdad846e00a648cfd4e2c40ea0a6037be624 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 14 Apr 2009 19:57:00 +0200 Subject: [PATCH] bringing docs and funcargs in sync --HG-- branch : trunk --- doc/test/funcargs.txt | 17 ++++++++++++++--- py/test/dist/testing/test_nodemanage.py | 2 +- py/test/plugin/pytest_pytester.py | 6 +++--- py/test/plugin/pytest_tmpdir.py | 2 +- py/test/pycollect.py | 13 ++++++------- py/test/testing/test_funcargs.py | 8 ++++---- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/doc/test/funcargs.txt b/doc/test/funcargs.txt index 491937f23..db2c0f3b9 100644 --- a/doc/test/funcargs.txt +++ b/doc/test/funcargs.txt @@ -2,7 +2,6 @@ **funcargs**: powerful and simple test setup ====================================================== - In version 1.0 py.test introduces a new mechanism for setting up test state for use by Python test functions. It is particularly useful for functional and integration testing but also for unit testing. @@ -170,9 +169,21 @@ into ``myapp.py``: def question(self): return 6 * 9 -You can now run the test with ``py.test test_sample.py``: +You can now run the test with ``py.test test_sample.py`` which will +show this failure: -.. sourcecode:: python +.. sourcecode:: python + + def test_answer(mysetup): + app = mysetup.myapp() + answer = app.question() + > assert answer == 42 + E assert 54 == 42 + +If you are confused as to that the question or answer is +here, please visit here_. + +.. _here: http://uncyclopedia.wikia.com/wiki/The_Hitchhiker's_Guide_to_the_Galaxy .. _`local plugin`: ext.html#local-plugin diff --git a/py/test/dist/testing/test_nodemanage.py b/py/test/dist/testing/test_nodemanage.py index b03bec989..a5097a926 100644 --- a/py/test/dist/testing/test_nodemanage.py +++ b/py/test/dist/testing/test_nodemanage.py @@ -4,7 +4,7 @@ from py.__.test.dist.nodemanage import NodeManager class pytest_funcarg__mysetup: def __init__(self, request): basetemp = request.config.ensuretemp(request.getfspath().purebasename) - basetemp = basetemp.mkdir(request.funcname) + basetemp = basetemp.mkdir(request.function.__name__) self.source = basetemp.mkdir("source") self.dest = basetemp.mkdir("dest") diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index 0a51707b5..080bbd063 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -42,7 +42,7 @@ class TmpTestdir: self.request = request # XXX remove duplication with tmpdir plugin basetmp = request.config.ensuretemp("testdir") - name = request.funcname + name = request.function.__name__ for i in range(100): try: tmpdir = basetmp.mkdir(name + str(i)) @@ -90,7 +90,7 @@ class TmpTestdir: items = kwargs.items() if args: source = "\n".join(map(str, args)) - basename = self.request.funcname + basename = self.request.function.__name__ items.insert(0, (basename, source)) ret = None for name, value in items: @@ -200,7 +200,7 @@ class TmpTestdir: return self.config.getfsnode(path) def getmodulecol(self, source, configargs=(), withinit=False): - kw = {self.request.funcname: py.code.Source(source).strip()} + kw = {self.request.function.__name__: py.code.Source(source).strip()} path = self.makepyfile(**kw) if withinit: self.makepyfile(__init__ = "#") diff --git a/py/test/plugin/pytest_tmpdir.py b/py/test/plugin/pytest_tmpdir.py index 307ab470e..fa3ec98d9 100644 --- a/py/test/plugin/pytest_tmpdir.py +++ b/py/test/plugin/pytest_tmpdir.py @@ -14,7 +14,7 @@ class TmpdirPlugin: """ def pytest_funcarg__tmpdir(self, request): - name = request.funcname + name = request.function.__name__ return request.config.mktemp(name, numbered=True) # =============================================================================== diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 521006abd..893643672 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -399,10 +399,9 @@ class FuncargRequest: def __init__(self, pyfuncitem, argname): # XXX make pyfuncitem _pyfuncitem - self.pyfuncitem = pyfuncitem + self._pyfuncitem = pyfuncitem self.argname = argname self.function = pyfuncitem.obj - self.funcname = pyfuncitem.name self.config = pyfuncitem.config self._plugins = self._getplugins() self._methods = self.config.pluginmanager.listattr( @@ -411,12 +410,12 @@ class FuncargRequest: ) def __repr__(self): - return "" %(self.argname, self.pyfuncitem) + return "" %(self.argname, self._pyfuncitem) def _getplugins(self): plugins = [] - current = self.pyfuncitem + current = self._pyfuncitem while not isinstance(current, Module): current = current.parent if isinstance(current, (Instance, Module)): @@ -430,10 +429,10 @@ class FuncargRequest: return nextmethod(request=self) def addfinalizer(self, finalizer): - self.pyfuncitem.addfinalizer(finalizer) + self._pyfuncitem.addfinalizer(finalizer) def getfspath(self): - return self.pyfuncitem.fspath + return self._pyfuncitem.fspath def _raiselookupfailed(self): available = [] @@ -443,7 +442,7 @@ class FuncargRequest: name = name[len(self._argprefix):] if name not in available: available.append(name) - metainfo = self.pyfuncitem.repr_metainfo() + metainfo = self._pyfuncitem.repr_metainfo() msg = "funcargument %r not found for: %s" %(self.argname,metainfo.verboseline()) msg += "\n available funcargs: %s" %(", ".join(available),) raise LookupError(msg) diff --git a/py/test/testing/test_funcargs.py b/py/test/testing/test_funcargs.py index ca9b4bcca..cee4681b2 100644 --- a/py/test/testing/test_funcargs.py +++ b/py/test/testing/test_funcargs.py @@ -16,7 +16,7 @@ class TestFuncargs: item = testdir.getitem("def test_func(some, other=42): pass") class Provider: def pytest_funcarg__some(self, request): - return request.funcname + return request.function.__name__ item.config.pluginmanager.register(Provider()) item.setupargs() assert len(item.funcargs) == 1 @@ -25,7 +25,7 @@ class TestFuncargs: item = testdir.getitem("def test_func(some=42, other=13): pass") class Provider: def pytest_funcarg__other(self, request): - return request.funcname + return request.function.__name__ item.config.pluginmanager.register(Provider()) item.setupargs() assert len(item.funcargs) == 1 @@ -37,7 +37,7 @@ class TestFuncargs: item = testdir.getitem("def test_func(some, other): pass") class Provider: def pytest_funcarg__some(self, request): - return request.funcname + return request.function.__name__ def pytest_funcarg__other(self, request): return 42 item.config.pluginmanager.register(Provider()) @@ -49,7 +49,7 @@ class TestFuncargs: def test_funcarg_lookup_modulelevel(self, testdir): modcol = testdir.getmodulecol(""" def pytest_funcarg__something(request): - return request.funcname + return request.function.__name__ class TestClass: def test_method(self, something):