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:
parent
a20e60aeae
commit
f3e62e38aa
|
@ -21,6 +21,10 @@ Changes between 1.X and 1.1.1
|
||||||
|
|
||||||
- new "pytestconfig" funcarg allows access to test config object
|
- 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
|
- automatically skip tests that need 'capfd' but have no os.dup
|
||||||
|
|
||||||
- allow pytest_generate_tests to be defined in classes as well
|
- allow pytest_generate_tests to be defined in classes as well
|
||||||
|
|
|
@ -79,10 +79,10 @@ class Config(object):
|
||||||
setattr(self.option, opt.dest, opt.default)
|
setattr(self.option, opt.dest, opt.default)
|
||||||
|
|
||||||
def _preparse(self, args):
|
def _preparse(self, args):
|
||||||
self._conftest.setinitial(args)
|
|
||||||
self.pluginmanager.consider_setuptools_entrypoints()
|
self.pluginmanager.consider_setuptools_entrypoints()
|
||||||
self.pluginmanager.consider_preparse(args)
|
|
||||||
self.pluginmanager.consider_env()
|
self.pluginmanager.consider_env()
|
||||||
|
self.pluginmanager.consider_preparse(args)
|
||||||
|
self._conftest.setinitial(args)
|
||||||
self.pluginmanager.do_addoption(self._parser)
|
self.pluginmanager.do_addoption(self._parser)
|
||||||
|
|
||||||
def parse(self, args):
|
def parse(self, args):
|
||||||
|
|
|
@ -85,10 +85,11 @@ class PluginManager(object):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return # XXX issue a warning
|
return # XXX issue a warning
|
||||||
for ep in iter_entry_points('pytest11'):
|
for ep in iter_entry_points('pytest11'):
|
||||||
if ep.name in self._name2plugin:
|
name = canonical_importname(ep.name)
|
||||||
|
if name in self._name2plugin:
|
||||||
continue
|
continue
|
||||||
plugin = ep.load()
|
plugin = ep.load()
|
||||||
self.register(plugin, name=ep.name)
|
self.register(plugin, name=name)
|
||||||
|
|
||||||
def consider_preparse(self, args):
|
def consider_preparse(self, args):
|
||||||
for opt1,opt2 in zip(args, args[1:]):
|
for opt1,opt2 in zip(args, args[1:]):
|
||||||
|
|
|
@ -237,3 +237,24 @@ def test_ensuretemp(recwarn):
|
||||||
d2 = py.test.ensuretemp('hello')
|
d2 = py.test.ensuretemp('hello')
|
||||||
assert d1 == d2
|
assert d1 == d2
|
||||||
assert d1.check(dir=1)
|
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
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,8 @@ class TestBootstrapping:
|
||||||
pluginmanager.consider_setuptools_entrypoints()
|
pluginmanager.consider_setuptools_entrypoints()
|
||||||
plugin = pluginmanager.getplugin("mytestplugin")
|
plugin = pluginmanager.getplugin("mytestplugin")
|
||||||
assert plugin.x == 42
|
assert plugin.x == 42
|
||||||
|
plugin2 = pluginmanager.getplugin("pytest_mytestplugin")
|
||||||
|
assert plugin2 == plugin
|
||||||
|
|
||||||
def test_consider_setuptools_not_installed(self, monkeypatch):
|
def test_consider_setuptools_not_installed(self, monkeypatch):
|
||||||
monkeypatch.setitem(py.std.sys.modules, 'pkg_resources',
|
monkeypatch.setitem(py.std.sys.modules, 'pkg_resources',
|
||||||
|
|
Loading…
Reference in New Issue