streamlined plugin loading: order is now setuptools, ENV, commandline

and setuptools entry point names are turned to canonical namees ("pytest_*")

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-01-02 17:17:13 +01:00
parent a20e60aeae
commit f3e62e38aa
5 changed files with 32 additions and 4 deletions

View File

@ -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

View File

@ -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):

View File

@ -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:]):

View File

@ -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

View File

@ -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',