fixes #3
added tests and fix for early parsing of "-p" option --HG-- branch : trunk
This commit is contained in:
parent
3a9d2873b5
commit
c8de661ef6
|
@ -76,6 +76,7 @@ class Config(object):
|
||||||
|
|
||||||
def _preparse(self, args):
|
def _preparse(self, args):
|
||||||
self._conftest.setinitial(args)
|
self._conftest.setinitial(args)
|
||||||
|
self.pluginmanager.consider_preparse(args)
|
||||||
self.pluginmanager.consider_env()
|
self.pluginmanager.consider_env()
|
||||||
self.pluginmanager.do_addoption(self._parser)
|
self.pluginmanager.do_addoption(self._parser)
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,11 @@ class PluginManager(object):
|
||||||
for spec in self._envlist("PYTEST_PLUGINS"):
|
for spec in self._envlist("PYTEST_PLUGINS"):
|
||||||
self.import_plugin(spec)
|
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):
|
def consider_conftest(self, conftestmodule):
|
||||||
cls = getattr(conftestmodule, 'ConftestPlugin', None)
|
cls = getattr(conftestmodule, 'ConftestPlugin', None)
|
||||||
if cls is not None and cls not in self.impname2plugin:
|
if cls is not None and cls not in self.impname2plugin:
|
||||||
|
|
|
@ -17,6 +17,23 @@ class TestGeneralUsage:
|
||||||
'*ERROR: hello'
|
'*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):
|
def test_basetemp(self, testdir):
|
||||||
mytemp = testdir.tmpdir.mkdir("mytemp")
|
mytemp = testdir.tmpdir.mkdir("mytemp")
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
|
|
|
@ -8,6 +8,12 @@ class TestBootstrapping:
|
||||||
monkeypatch.setitem(os.environ, 'PYTEST_PLUGINS', 'nonexistingmodule')
|
monkeypatch.setitem(os.environ, 'PYTEST_PLUGINS', 'nonexistingmodule')
|
||||||
py.test.raises(ImportError, "pluginmanager.consider_env()")
|
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):
|
def test_consider_env_plugin_instantiation(self, testdir, monkeypatch):
|
||||||
pluginmanager = PluginManager()
|
pluginmanager = PluginManager()
|
||||||
testdir.syspathinsert()
|
testdir.syspathinsert()
|
||||||
|
|
Loading…
Reference in New Issue