[svn r63177] add a "-p" option to allow to add plugins from the command line.
--HG-- branch : trunk
This commit is contained in:
parent
a2e7b1433e
commit
8dd1dd24bc
|
@ -27,8 +27,8 @@ version = "1.0.0a2"
|
||||||
|
|
||||||
initpkg(__name__,
|
initpkg(__name__,
|
||||||
description = "pylib and py.test: agile development and test support library",
|
description = "pylib and py.test: agile development and test support library",
|
||||||
revision = int('$LastChangedRevision: 63164 $'.split(':')[1][:-1]),
|
revision = int('$LastChangedRevision: 63177 $'.split(':')[1][:-1]),
|
||||||
lastchangedate = '$LastChangedDate: 2009-03-21 03:21:45 +0100 (Sat, 21 Mar 2009) $',
|
lastchangedate = '$LastChangedDate: 2009-03-21 14:54:39 +0100 (Sat, 21 Mar 2009) $',
|
||||||
version = version,
|
version = version,
|
||||||
url = "http://pylib.org",
|
url = "http://pylib.org",
|
||||||
download_url = "http://codespeak.net/py/%s/download.html" % version,
|
download_url = "http://codespeak.net/py/%s/download.html" % version,
|
||||||
|
@ -38,7 +38,7 @@ initpkg(__name__,
|
||||||
author_email = "holger at merlinux.eu, py-dev at codespeak.net",
|
author_email = "holger at merlinux.eu, py-dev at codespeak.net",
|
||||||
long_description = globals()['__doc__'],
|
long_description = globals()['__doc__'],
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 4 - Beta",
|
"Development Status :: 3 - Alpha",
|
||||||
"Intended Audience :: Developers",
|
"Intended Audience :: Developers",
|
||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: POSIX",
|
"Operating System :: POSIX",
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DefaultPlugin:
|
||||||
return Directory(path, parent=parent)
|
return Directory(path, parent=parent)
|
||||||
|
|
||||||
def pytest_addoption(self, parser):
|
def pytest_addoption(self, parser):
|
||||||
group = parser.addgroup("general", "general options")
|
group = parser.addgroup("general", "test selection and failure debug options")
|
||||||
group._addoption('-v', '--verbose', action="count",
|
group._addoption('-v', '--verbose', action="count",
|
||||||
dest="verbose", default=0, help="increase verbosity."),
|
dest="verbose", default=0, help="increase verbosity."),
|
||||||
group._addoption('-x', '--exitfirst',
|
group._addoption('-x', '--exitfirst',
|
||||||
|
@ -68,7 +68,11 @@ class DefaultPlugin:
|
||||||
help="temporary directory for this test run.")
|
help="temporary directory for this test run.")
|
||||||
group.addoption('--boxed',
|
group.addoption('--boxed',
|
||||||
action="store_true", dest="boxed", default=False,
|
action="store_true", dest="boxed", default=False,
|
||||||
help="box each test run in a separate process"),
|
help="box each test run in a separate process")
|
||||||
|
group._addoption('--plugin', '-p', action="append", dest="plugin", default = [],
|
||||||
|
help=("load the specified plugin after command line parsing. "
|
||||||
|
"Example: '-p hello' will trigger 'import pytest_hello' "
|
||||||
|
"and instantiate 'HelloPlugin' from the module."))
|
||||||
group._addoption('-f', '--looponfailing',
|
group._addoption('-f', '--looponfailing',
|
||||||
action="store_true", dest="looponfailing", default=False,
|
action="store_true", dest="looponfailing", default=False,
|
||||||
help="loop on failing test set.")
|
help="loop on failing test set.")
|
||||||
|
@ -117,6 +121,12 @@ class DefaultPlugin:
|
||||||
|
|
||||||
def pytest_configure(self, config):
|
def pytest_configure(self, config):
|
||||||
self.setsession(config)
|
self.setsession(config)
|
||||||
|
self.loadplugins(config)
|
||||||
|
|
||||||
|
def loadplugins(self, config):
|
||||||
|
for name in config.getvalue("plugin"):
|
||||||
|
print "importing", name
|
||||||
|
config.pytestplugins.import_plugin(name)
|
||||||
|
|
||||||
def setsession(self, config):
|
def setsession(self, config):
|
||||||
val = config.getvalue
|
val = config.getvalue
|
||||||
|
@ -149,3 +159,19 @@ def test_implied_different_sessions(tmpdir):
|
||||||
assert x('--exec=x') == 'DSession'
|
assert x('--exec=x') == 'DSession'
|
||||||
assert x('-f', '--exec=x') == 'LooponfailingSession'
|
assert x('-f', '--exec=x') == 'LooponfailingSession'
|
||||||
assert x('--dist', '--exec=x', '--collectonly') == 'Session'
|
assert x('--dist', '--exec=x', '--collectonly') == 'Session'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_generic(plugintester):
|
||||||
|
plugintester.apicheck(DefaultPlugin)
|
||||||
|
|
||||||
|
def test_plugin_specify(testdir):
|
||||||
|
testdir.chdir()
|
||||||
|
config = testdir.parseconfig("-p", "nqweotexistent")
|
||||||
|
py.test.raises(ImportError,
|
||||||
|
"config.pytestplugins.do_configure(config)"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_plugin_already_exists(testdir):
|
||||||
|
config = testdir.parseconfig("--plugin", "default")
|
||||||
|
assert config.option.plugin == ['default']
|
||||||
|
|
Loading…
Reference in New Issue