2 new commits in pytest: https://bitbucket.org/hpk42/pytest/commits/a59fa6c971ab/ Changeset: a59fa6c971ab User: flub Date: 2013-07-06 17:56:54 Summary: Solve fixture ordering when loading plugins from conftest
Conftests are plugins with a location attached to them while other plugins do not have a location. When ordering fixturedefs those from plugins without a location need to be listed first. Affected #: 2 files diff -r 63b5f85e68df7242019300937e01d247f89e9361 -r a59fa6c971abd42810301100464c4da7bc363e1d _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1472,8 +1472,7 @@ def pytest_plugin_registered(self, plugin): if plugin in self._seenplugins: return - #print "plugin_registered", plugin - nodeid = "" + nodeid = None try: p = py.path.local(plugin.__file__) except AttributeError: @@ -1580,8 +1579,8 @@ for fin in reversed(l): fin() - def parsefactories(self, node_or_obj, nodeid=None, unittest=False): - if nodeid is not None: + def parsefactories(self, node_or_obj, nodeid=_dummy, unittest=False): + if nodeid is not _dummy: holderobj = node_or_obj else: holderobj = node_or_obj.obj @@ -1612,7 +1611,15 @@ marker.scope, marker.params, unittest=unittest) faclist = self._arg2fixturedefs.setdefault(name, []) - faclist.append(fixturedef) + if not fixturedef.has_location: + # All Nones are at the front so this inserts the + # current fixturedef after the existing fixturedefs + # from external plugins but before the fixturedefs + # provided in conftests. + i = faclist.count(None) + else: + i = len(faclist) # append + faclist.insert(i, fixturedef) if marker.autouse: autousenames.append(name) if autousenames: @@ -1670,7 +1677,8 @@ def __init__(self, fixturemanager, baseid, argname, func, scope, params, unittest=False): self._fixturemanager = fixturemanager - self.baseid = baseid + self.baseid = baseid or '' + self.has_location = baseid is not None self.func = func self.argname = argname self.scope = scope @@ -1721,7 +1729,8 @@ return result def __repr__(self): - return "<FixtureDef name=%r scope=%r>" % (self.argname, self.scope) + return ("<FixtureDef name=%r scope=%r baseid=%r module=%r>" % + (self.argname, self.scope, self.baseid, self.func.__module__)) def getfuncargnames(function, startindex=None): # XXX merge with main.py's varnames diff -r 63b5f85e68df7242019300937e01d247f89e9361 -r a59fa6c971abd42810301100464c4da7bc363e1d testing/python/fixture.py --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -173,6 +173,31 @@ result = testdir.runpytest(testfile) result.stdout.fnmatch_lines(["*1 passed*"]) + def test_extend_fixture_conftest_plugin(request, testdir): + testdir.makepyfile(testplugin=""" + import pytest + + @pytest.fixture + def foo(): + return 7 + """) + testdir.syspathinsert() + testdir.makeconftest(""" + import pytest + + pytest_plugins = 'testplugin' + + @pytest.fixture + def foo(foo): + return foo + 7 + """) + testdir.makepyfile(""" + def test_foo(foo): + assert foo == 14 + """) + result = testdir.runpytest('-s') + assert result.ret == 0 + def test_funcarg_lookup_error(self, testdir): p = testdir.makepyfile(""" def test_lookup_error(unknown): https://bitbucket.org/hpk42/pytest/commits/cc8871c02a5e/ Changeset: cc8871c02a5e User: flub Date: 2013-07-06 18:53:26 Summary: Always check for both ENOENT and ENOTDIR This fixes issue 326. Affected #: 1 file diff -r a59fa6c971abd42810301100464c4da7bc363e1d -r cc8871c02a5e4e34ad8e42121ffefb0651304b67 _pytest/assertion/rewrite.py --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -15,12 +15,6 @@ from _pytest.assertion import util -# Windows gives ENOENT in places *nix gives ENOTDIR. -if sys.platform.startswith("win"): - PATH_COMPONENT_NOT_DIR = errno.ENOENT -else: - PATH_COMPONENT_NOT_DIR = errno.ENOTDIR - # py.test caches rewritten pycs in __pycache__. if hasattr(imp, "get_tag"): PYTEST_TAG = imp.get_tag() + "-PYTEST" @@ -119,7 +113,7 @@ # common case) or it's blocked by a non-dir node. In the # latter case, we'll ignore it in _write_pyc. pass - elif e == PATH_COMPONENT_NOT_DIR: + elif e in [errno.ENOENT, errno.ENOTDIR]: # One of the path components was not a directory, likely # because we're in a zip file. write = False @@ -173,7 +167,7 @@ fp = open(pyc, "wb") except IOError: err = sys.exc_info()[1].errno - if err == PATH_COMPONENT_NOT_DIR: + if err in [errno.ENOENT, errno.ENOTDIR]: # This happens when we get a EEXIST in find_module creating the # __pycache__ directory and __pycache__ is by some non-dir node. return False Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org http://mail.python.org/mailman/listinfo/pytest-commit