[svn r58300] adding option to specify namespace for ifraises execution.
--HG-- branch : trunk
This commit is contained in:
parent
13c7fb6709
commit
fa5c975c00
|
@ -49,19 +49,22 @@ def exit(msg):
|
|||
__tracebackhide__ = True
|
||||
raise Exit(msg)
|
||||
|
||||
def skip(msg="", ifraises=None):
|
||||
def skip(msg="", ifraises=None, ns=None):
|
||||
""" (conditionally) skip this test/module/conftest.
|
||||
|
||||
msg: use this message when skipping.
|
||||
ifraises:
|
||||
if "exec ifraises in {'py': py}" raises an exception
|
||||
skip this test.
|
||||
msg: use this message when skipping.
|
||||
ns: use this namespace when executing ifraises
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
if ifraises is not None:
|
||||
ifraises = py.code.Source(ifraises).compile()
|
||||
if ns is None:
|
||||
ns = {}
|
||||
try:
|
||||
exec ifraises in {'py': py}
|
||||
exec ifraises in ns
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception, e:
|
||||
|
|
|
@ -387,10 +387,7 @@ class TestPyTest(AcceptBase):
|
|||
|
||||
class TestInteractive(AcceptBase):
|
||||
def getspawn(self):
|
||||
try:
|
||||
import pexpect
|
||||
except ImportError:
|
||||
py.test.skip("cannot import pexpect")
|
||||
py.test.skip(ifraises="import pexpect", ns=globals())
|
||||
def spawn(cmd):
|
||||
return pexpect.spawn(cmd, logfile=self.tmpdir.join("spawn.out").open("w"))
|
||||
return spawn
|
||||
|
|
|
@ -76,6 +76,11 @@ def test_skip_ifraises():
|
|||
assert excinfo.traceback[-1].ishidden()
|
||||
assert excinfo.value.msg.startswith("ImportError")
|
||||
|
||||
def test_skip_ifraises_ns():
|
||||
d = {}
|
||||
py.test.skip(ns=d, ifraises="import py")
|
||||
assert d['py'] == py
|
||||
|
||||
def test_skip_ifraises_syntaxerror():
|
||||
try:
|
||||
excinfo = py.test.raises(SyntaxError, '''
|
||||
|
|
Loading…
Reference in New Issue