From f3e62e38aa3569257f41d45ed0cbe8c9bcf2ac5d Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 2 Jan 2010 17:17:13 +0100 Subject: [PATCH] streamlined plugin loading: order is now setuptools, ENV, commandline and setuptools entry point names are turned to canonical namees ("pytest_*") --HG-- branch : trunk --- CHANGELOG | 4 ++++ py/impl/test/config.py | 4 ++-- py/impl/test/pluginmanager.py | 5 +++-- testing/pytest/test_config.py | 21 +++++++++++++++++++++ testing/pytest/test_pluginmanager.py | 2 ++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8d4540124..4bac2e2bf 100644 --- 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 diff --git a/py/impl/test/config.py b/py/impl/test/config.py index 7ad036bee..4a47748c2 100644 --- 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._conftest.setinitial(args) self.pluginmanager.consider_setuptools_entrypoints() - self.pluginmanager.consider_preparse(args) self.pluginmanager.consider_env() + self.pluginmanager.consider_preparse(args) + self._conftest.setinitial(args) self.pluginmanager.do_addoption(self._parser) def parse(self, args): diff --git a/py/impl/test/pluginmanager.py b/py/impl/test/pluginmanager.py index 5bda34ca5..90fbd6884 100644 --- 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:]): diff --git a/testing/pytest/test_config.py b/testing/pytest/test_config.py index b139aa062..10e3bd50d 100644 --- 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 + diff --git a/testing/pytest/test_pluginmanager.py b/testing/pytest/test_pluginmanager.py index 0ab444185..7f164d2a5 100644 --- 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',