unittest.py patch: add skipped test functionality
Remy Blank
remy.blank_asps at pobox.com
Fri Sep 24 05:08:44 EDT 2004
Ok, here we go.
I added the possibility for tests using the unittest.py framework
to be skipped. Basically, I added two methods to TestCase:
TestCase.skip(msg): skips unconditionally
TestCase.skipIf(expr, msg): skips if expr is true
These can be called either in setUp() or in the test methods. I also
added reporting of skipped tests to TestResult, _TextTestResult and
TextTestRunner. If no tests are skipped, everything should be the
same as before.
I am using Python 2.3.3, so the changes are against the file in that
version. I attached the patch against the original
(unittest_skip.patch), a complete test suite for the new functionality
(testSkippedTest.py) and a usage example (SkippedTestDemo.py).
I would welcome any feedback about the idea, the implementation,
suggestions for improvements, fixes, etc.
I would also like to know if this would be a candidate for inclusion
into the unittest.py provided with Python. I suppose I should
contact Steve Purcell directly for that.
-- Remy
Quick usage example:
class ReadShadowTest(unittest.TestCase):
"""Read access to /etc/shadow"""
def testReadingAsRoot(self):
"""Reading /etc/shadow as root"""
self.skipIf(os.geteuid() != 0, "Must be root")
open("/etc/shadow").close()
The attached example (SkippedTestDemo.py) produces the following output:
$ ./SkippedTestDemo.py -v
Access to autoexec.bat ... SKIPPED (Only available on Windows)
Access to config.sys ... SKIPPED (Only available on Windows)
Reading /etc/shadow as root ... SKIPPED (Must be root)
Reading /etc/shadow as non-root ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.004s
OK (skipped=3)
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: unittest_skip.patch
URL: <http://mail.python.org/pipermail/python-list/attachments/20040924/b92235be/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testSkippedTest.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20040924/b92235be/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: SkippedTestDemo.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20040924/b92235be/attachment-0002.ksh>
More information about the Python-list
mailing list