[py-svn] py-trunk commit fbcfccc6887e: streamlined plugin loading: order is now setuptools, ENV, commandline
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sat Jan 2 17:17:33 CET 2010
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1262449033 -3600
# Node ID fbcfccc6887ed019ba72c56e44bbde99117183a8
# Parent 546b8924bbff4fbf57601b90da430e1f7238f3a2
streamlined plugin loading: order is now setuptools, ENV, commandline
and setuptools entry point names are turned to canonical namees ("pytest_*")
--- a/testing/pytest/test_pluginmanager.py
+++ b/testing/pytest/test_pluginmanager.py
@@ -61,6 +61,8 @@ class TestBootstrapping:
pluginmanager.consider_setuptools_entrypoints()
plugin = pluginmanager.getplugin("mytestplugin")
assert plugin.x == 42
+ plugin2 = pluginmanager.getplugin("pytest_mytestplugin")
+ assert plugin2 == plugin
def test_consider_setuptools_not_installed(self, monkeypatch):
monkeypatch.setitem(py.std.sys.modules, 'pkg_resources',
--- a/testing/pytest/test_config.py
+++ b/testing/pytest/test_config.py
@@ -237,3 +237,24 @@ def test_ensuretemp(recwarn):
d2 = py.test.ensuretemp('hello')
assert d1 == d2
assert d1.check(dir=1)
+
+def test_preparse_ordering(testdir, monkeypatch):
+ pkg_resources = py.test.importorskip("pkg_resources")
+ def my_iter(name):
+ assert name == "pytest11"
+ class EntryPoint:
+ name = "mytestplugin"
+ def load(self):
+ class PseudoPlugin:
+ x = 42
+ return PseudoPlugin()
+ return iter([EntryPoint()])
+ monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
+ testdir.makeconftest("""
+ pytest_plugins = "mytestplugin",
+ """)
+ monkeypatch.setenv("PYTEST_PLUGINS", "mytestplugin")
+ config = testdir.parseconfig()
+ plugin = config.pluginmanager.getplugin("mytestplugin")
+ assert plugin.x == 42
+
--- a/py/impl/test/config.py
+++ b/py/impl/test/config.py
@@ -79,10 +79,10 @@ class Config(object):
setattr(self.option, opt.dest, opt.default)
def _preparse(self, args):
+ self.pluginmanager.consider_setuptools_entrypoints()
+ self.pluginmanager.consider_env()
+ self.pluginmanager.consider_preparse(args)
self._conftest.setinitial(args)
- self.pluginmanager.consider_setuptools_entrypoints()
- self.pluginmanager.consider_preparse(args)
- self.pluginmanager.consider_env()
self.pluginmanager.do_addoption(self._parser)
def parse(self, args):
--- a/py/impl/test/pluginmanager.py
+++ b/py/impl/test/pluginmanager.py
@@ -85,10 +85,11 @@ class PluginManager(object):
except ImportError:
return # XXX issue a warning
for ep in iter_entry_points('pytest11'):
- if ep.name in self._name2plugin:
+ name = canonical_importname(ep.name)
+ if name in self._name2plugin:
continue
plugin = ep.load()
- self.register(plugin, name=ep.name)
+ self.register(plugin, name=name)
def consider_preparse(self, args):
for opt1,opt2 in zip(args, args[1:]):
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -21,6 +21,10 @@ Changes between 1.X and 1.1.1
- new "pytestconfig" funcarg allows access to test config object
+- streamlined plugin loading: order is now as documented in
+ customize.html: setuptools, ENV, commandline, conftest.
+ also setuptools entry point names are turned to canonical namees ("pytest_*")
+
- automatically skip tests that need 'capfd' but have no os.dup
- allow pytest_generate_tests to be defined in classes as well
More information about the pytest-commit
mailing list