[svn r45648] Add possibility to specify reason for skips
--HG-- branch : trunk
This commit is contained in:
parent
a7a95973eb
commit
773848823d
|
@ -70,7 +70,25 @@ class Function(FunctionMixin, Item):
|
|||
#
|
||||
# triggering specific outcomes while executing Items
|
||||
#
|
||||
def skip(msg="unknown reason"):
|
||||
class BaseReason(object):
|
||||
def __init__(self, msg="unknown reason", **kwds):
|
||||
self.msg = msg
|
||||
self.__dict__.update(kwds)
|
||||
|
||||
def __repr__(self):
|
||||
return self.msg
|
||||
|
||||
class Broken(BaseReason):
|
||||
def __repr__(self):
|
||||
return "Broken: %s" % (self.msg,)
|
||||
|
||||
class _NotImplemented(BaseReason):
|
||||
def __repr__(self):
|
||||
return "Not implemented: %s" % (self.msg,)
|
||||
|
||||
# whatever comes here....
|
||||
|
||||
def skip(msg=BaseReason()):
|
||||
""" skip with the given Message. """
|
||||
__tracebackhide__ = True
|
||||
raise Skipped(msg=msg)
|
||||
|
|
|
@ -325,3 +325,24 @@ class TestTerminalSession:
|
|||
expected_output = '\nE ' + line_to_report + '\n'
|
||||
print 'Looking for:', expected_output
|
||||
assert expected_output in out
|
||||
|
||||
|
||||
def test_skip_reasons():
|
||||
tmp = py.test.ensuretemp("check_skip_reasons")
|
||||
tmp.ensure("test_one.py").write(py.code.Source("""
|
||||
import py
|
||||
def test_1():
|
||||
py.test.skip(py.test.broken('stuff'))
|
||||
|
||||
def test_2():
|
||||
py.test.skip(py.test.notimplemented('stuff'))
|
||||
"""))
|
||||
tmp.ensure("__init__.py")
|
||||
config = py.test.config._reparse([tmp])
|
||||
session = config.initsession()
|
||||
session.main()
|
||||
skips = session.getitemoutcomepairs(Skipped)
|
||||
assert len(skips) == 2
|
||||
assert repr(skips[0][1]) == 'Broken: stuff'
|
||||
assert repr(skips[1][1]) == 'Not implemented: stuff'
|
||||
|
||||
|
|
Loading…
Reference in New Issue