[svn r62982] report basic configuration errors more gracefully to the user
--HG-- branch : trunk
This commit is contained in:
parent
771ce92fdf
commit
bbdebac87a
|
@ -9,12 +9,16 @@ def main(args=None):
|
|||
if args is None:
|
||||
args = py.std.sys.argv[1:]
|
||||
config = py.test.config
|
||||
try:
|
||||
config.parse(args)
|
||||
config.pytestplugins.do_configure(config)
|
||||
session = config.initsession()
|
||||
exitstatus = session.main()
|
||||
config.pytestplugins.do_unconfigure(config)
|
||||
raise SystemExit(exitstatus)
|
||||
except config.Error, e:
|
||||
py.std.sys.stderr.write("config ERROR: %s\n" %(e.args[0],))
|
||||
raise SystemExit(3)
|
||||
|
||||
def warn_about_missing_assertion():
|
||||
try:
|
||||
|
|
|
@ -22,9 +22,13 @@ class CmdOptions(object):
|
|||
def __repr__(self):
|
||||
return "<CmdOptions %r>" %(self.__dict__,)
|
||||
|
||||
class Error(Exception):
|
||||
""" Test Configuration Error. """
|
||||
|
||||
class Config(object):
|
||||
""" central bus for dealing with configuration/initialization data. """
|
||||
Option = py.compat.optparse.Option # deprecated
|
||||
Error = Error
|
||||
_sessionclass = None
|
||||
|
||||
def __init__(self, pytestplugins=None, topdir=None):
|
||||
|
@ -124,7 +128,8 @@ class Config(object):
|
|||
|
||||
def getfsnode(self, path):
|
||||
path = py.path.local(path)
|
||||
assert path.check(), "%s: path does not exist" %(path,)
|
||||
if not path.check():
|
||||
raise self.Error("file not found: %s" %(path,))
|
||||
# we want our possibly custom collection tree to start at pkgroot
|
||||
pkgpath = path.pypkgpath()
|
||||
if pkgpath is None:
|
||||
|
|
|
@ -5,6 +5,18 @@ pytestpath = pydir.join("bin", "py.test")
|
|||
EXPECTTIMEOUT=10.0
|
||||
|
||||
class TestPyTest:
|
||||
def test_config_error(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
class ConftestPlugin:
|
||||
def pytest_configure(self, config):
|
||||
raise config.Error("hello")
|
||||
""")
|
||||
result = testdir.runpytest(testdir.tmpdir)
|
||||
assert result.ret != 0
|
||||
assert result.stderr.fnmatch_lines([
|
||||
'config ERROR: hello'
|
||||
])
|
||||
|
||||
def test_assertion_magic(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
def test_this():
|
||||
|
|
Loading…
Reference in New Issue