summaryrefslogtreecommitdiffstats
path: root/Doc/library/unittest.rst
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2010-02-28 03:48:50 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2010-02-28 03:48:50 (GMT)
commitc08cae9fa1b6241a192e0c878877914b000d6ce3 (patch)
treeec4c9ac787d5f18e5d924e8c0ffc3be76db7b938 /Doc/library/unittest.rst
parent1ca73ede26e05b656787122fea3ce9bd01a5f7f7 (diff)
downloadcpython-c08cae9fa1b6241a192e0c878877914b000d6ce3.zip
cpython-c08cae9fa1b6241a192e0c878877914b000d6ce3.tar.gz
cpython-c08cae9fa1b6241a192e0c878877914b000d6ce3.tar.bz2
Merged revisions 78513 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r78513 | ezio.melotti | 2010-02-28 05:46:13 +0200 (Sun, 28 Feb 2010) | 9 lines Merged revisions 78511 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78511 | ezio.melotti | 2010-02-28 05:11:07 +0200 (Sun, 28 Feb 2010) | 1 line Pep8ify test names in the examples. ........ ................
Diffstat (limited to 'Doc/library/unittest.rst')
-rw-r--r--Doc/library/unittest.rst34
1 files changed, 17 insertions, 17 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index bc7062c..7224bde 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -162,9 +162,9 @@ command line. For example, the last two lines may be replaced with::
Running the revised script from the interpreter or another script produces the
following output::
- testchoice (__main__.TestSequenceFunctions) ... ok
- testsample (__main__.TestSequenceFunctions) ... ok
- testshuffle (__main__.TestSequenceFunctions) ... ok
+ test_choice (__main__.TestSequenceFunctions) ... ok
+ test_sample (__main__.TestSequenceFunctions) ... ok
+ test_shuffle (__main__.TestSequenceFunctions) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.110s
@@ -283,32 +283,32 @@ mechanism::
self.widget.dispose()
self.widget = None
- def testDefaultSize(self):
+ def test_default_size(self):
self.assertEqual(self.widget.size(), (50,50),
'incorrect default size')
- def testResize(self):
+ def test_resize(self):
self.widget.resize(100,150)
self.assertEqual(self.widget.size(), (100,150),
'wrong size after resize')
Here we have not provided a :meth:`~TestCase.runTest` method, but have instead
provided two different test methods. Class instances will now each run one of
-the :meth:`test\*` methods, with ``self.widget`` created and destroyed
+the :meth:`test_\*` methods, with ``self.widget`` created and destroyed
separately for each instance. When creating an instance we must specify the
test method it is to run. We do this by passing the method name in the
constructor::
- defaultSizeTestCase = WidgetTestCase('testDefaultSize')
- resizeTestCase = WidgetTestCase('testResize')
+ defaultSizeTestCase = WidgetTestCase('test_default_size')
+ resizeTestCase = WidgetTestCase('test_resize')
Test case instances are grouped together according to the features they test.
:mod:`unittest` provides a mechanism for this: the :dfn:`test suite`,
represented by :mod:`unittest`'s :class:`TestSuite` class::
widgetTestSuite = unittest.TestSuite()
- widgetTestSuite.addTest(WidgetTestCase('testDefaultSize'))
- widgetTestSuite.addTest(WidgetTestCase('testResize'))
+ widgetTestSuite.addTest(WidgetTestCase('test_default_size'))
+ widgetTestSuite.addTest(WidgetTestCase('test_resize'))
For the ease of running tests, as we will see later, it is a good idea to
provide in each test module a callable object that returns a pre-built test
@@ -316,14 +316,14 @@ suite::
def suite():
suite = unittest.TestSuite()
- suite.addTest(WidgetTestCase('testDefaultSize'))
- suite.addTest(WidgetTestCase('testResize'))
+ suite.addTest(WidgetTestCase('test_default_size'))
+ suite.addTest(WidgetTestCase('test_resize'))
return suite
or even::
def suite():
- tests = ['testDefaultSize', 'testResize']
+ tests = ['test_default_size', 'test_resize']
return unittest.TestSuite(map(WidgetTestCase, tests))
@@ -334,8 +334,8 @@ populating it with individual tests. For example, ::
suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase)
-will create a test suite that will run ``WidgetTestCase.testDefaultSize()`` and
-``WidgetTestCase.testResize``. :class:`TestLoader` uses the ``'test'`` method
+will create a test suite that will run ``WidgetTestCase.test_default_size()`` and
+``WidgetTestCase.test_resize``. :class:`TestLoader` uses the ``'test'`` method
name prefix to identify test methods automatically.
Note that the order in which the various test cases will be run is
@@ -540,8 +540,8 @@ Test cases
def suite():
suite = unittest.TestSuite()
- suite.addTest(WidgetTestCase('testDefaultSize'))
- suite.addTest(WidgetTestCase('testResize'))
+ suite.addTest(WidgetTestCase('test_default_size'))
+ suite.addTest(WidgetTestCase('test_resize'))
return suite
Here, we create two instances of :class:`WidgetTestCase`, each of which runs a