[py-svn] r45648 - in py/trunk/py/test: . testing

fijal at codespeak.net fijal at codespeak.net
Tue Aug 14 11:48:16 CEST 2007


Author: fijal
Date: Tue Aug 14 11:48:15 2007
New Revision: 45648

Modified:
   py/trunk/py/test/item.py
   py/trunk/py/test/testing/test_session.py
Log:
Add possibility to specify reason for skips


Modified: py/trunk/py/test/item.py
==============================================================================
--- py/trunk/py/test/item.py	(original)
+++ py/trunk/py/test/item.py	Tue Aug 14 11:48:15 2007
@@ -70,7 +70,25 @@
 #
 # 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) 

Modified: py/trunk/py/test/testing/test_session.py
==============================================================================
--- py/trunk/py/test/testing/test_session.py	(original)
+++ py/trunk/py/test/testing/test_session.py	Tue Aug 14 11:48:15 2007
@@ -325,3 +325,24 @@
         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'
+    



More information about the pytest-commit mailing list