summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-22 20:08:14 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-22 20:08:14 (GMT)
commit1c48654e01506b224527da99eaaf9a493bc5cd2d (patch)
tree1016719a9a1c61a232bfdb8e1ac3e7ef55380817 /Lib/test
parent8ccd9b63cc14aa07b1f6ab4477772addcfc6ee89 (diff)
downloadcpython-1c48654e01506b224527da99eaaf9a493bc5cd2d.zip
cpython-1c48654e01506b224527da99eaaf9a493bc5cd2d.tar.gz
cpython-1c48654e01506b224527da99eaaf9a493bc5cd2d.tar.bz2
Document that docstrings are verboten for test functions.
Expand the example to show some actual test functions, and a setUp() and tearDown() method.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/README40
1 files changed, 34 insertions, 6 deletions
diff --git a/Lib/test/README b/Lib/test/README
index 9a3244f..40837e4 100644
--- a/Lib/test/README
+++ b/Lib/test/README
@@ -48,22 +48,50 @@ All test methods in the Python regression framework have names that
start with "test_" and use lower-case names with words separated with
underscores.
+Test methods should *not* have docstrings! The unittest module prints
+the docstring if there is one, but otherwise prints the function name
+and the full class name. When there's a problem with a test, the
+latter information makes it easier to find the source for the test
+than the docstring.
+
All PyUnit-based tests in the Python test suite use boilerplate that
-looks like this:
+looks like this (with minor variations):
import unittest
from test import test_support
class MyTestCase1(unittest.TestCase):
- # define test methods here...
+
+ # Define setUp and tearDown only if needed
+
+ def setUp(self):
+ unittest.TestCase.setUp(self)
+ ... additional initialization...
+
+ def tearDown(self):
+ ... additional finalization...
+ unittest.TestCase.tearDown(self)
+
+ def test_feature_one(self):
+ # Testing feature one
+ ...unit test for feature one...
+
+ def test_feature_two(self):
+ # Testing feature two
+ ...unit test for feature two...
+
+ ...etc...
class MyTestCase2(unittest.TestCase):
- # define more test methods here...
+ ...same structure as MyTestCase1...
+
+ ...etc...
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(MyTestCase1))
- suite.addTest(unittest.makeSuite(MyTestCase2))
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(MyTestCase1))
+ suite.addTest(unittest.makeSuite(MyTestCase2))
+ ...add more suites...
test_support.run_suite(suite)
if __name__ == "__main__":