added tests and fix for early parsing of "-p" option

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-04-17 20:09:29 +02:00
parent 3a9d2873b5
commit c8de661ef6
4 changed files with 29 additions and 0 deletions

View File

@ -76,6 +76,7 @@ class Config(object):
def _preparse(self, args):
self._conftest.setinitial(args)
self.pluginmanager.consider_preparse(args)
self.pluginmanager.consider_env()
self.pluginmanager.do_addoption(self._parser)

View File

@ -47,6 +47,11 @@ class PluginManager(object):
for spec in self._envlist("PYTEST_PLUGINS"):
self.import_plugin(spec)
def consider_preparse(self, args):
for opt1,opt2 in zip(args, args[1:]):
if opt1 == "-p":
self.import_plugin(opt2)
def consider_conftest(self, conftestmodule):
cls = getattr(conftestmodule, 'ConftestPlugin', None)
if cls is not None and cls not in self.impname2plugin:

View File

@ -17,6 +17,23 @@ class TestGeneralUsage:
'*ERROR: hello'
])
def test_config_preparse_plugin_option(self, testdir):
testdir.makepyfile(pytest_xyz="""
class XyzPlugin:
def pytest_addoption(self, parser):
parser.addoption("--xyz", dest="xyz", action="store")
""")
testdir.makepyfile(test_one="""
import py
def test_option():
assert py.test.config.option.xyz == "123"
""")
result = testdir.runpytest("-p", "xyz", "--xyz=123")
assert result.ret == 0
assert result.stdout.fnmatch_lines([
'*1 passed*',
])
def test_basetemp(self, testdir):
mytemp = testdir.tmpdir.mkdir("mytemp")
p = testdir.makepyfile("""

View File

@ -8,6 +8,12 @@ class TestBootstrapping:
monkeypatch.setitem(os.environ, 'PYTEST_PLUGINS', 'nonexistingmodule')
py.test.raises(ImportError, "pluginmanager.consider_env()")
def test_preparse_args(self, monkeypatch):
pluginmanager = PluginManager()
py.test.raises(ImportError, """
pluginmanager.consider_preparse(["xyz", "-p", "hello123"])
""")
def test_consider_env_plugin_instantiation(self, testdir, monkeypatch):
pluginmanager = PluginManager()
testdir.syspathinsert()