Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
68beef66
Commit
68beef66
authored
Feb 28, 2010
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pep8ify test names in the examples.
parent
78fd521f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
Doc/library/unittest.rst
Doc/library/unittest.rst
+17
-17
No files found.
Doc/library/unittest.rst
View file @
68beef66
...
...
@@ -165,9 +165,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
...
...
@@ -351,32 +351,32 @@ mechanism::
self.widget.dispose()
self.widget = None
def test
DefaultS
ize(self):
def test
_default_s
ize(self):
self.assertEqual(self.widget.size(), (50,50),
'incorrect default size')
def test
R
esize(self):
def test
_r
esize(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('test
DefaultS
ize')
resizeTestCase = WidgetTestCase('test
R
esize')
defaultSizeTestCase = WidgetTestCase('test
_default_s
ize')
resizeTestCase = WidgetTestCase('test
_r
esize')
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('test
DefaultS
ize'))
widgetTestSuite.addTest(WidgetTestCase('test
R
esize'))
widgetTestSuite.addTest(WidgetTestCase('test
_default_s
ize'))
widgetTestSuite.addTest(WidgetTestCase('test
_r
esize'))
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
...
...
@@ -384,14 +384,14 @@ suite::
def suite():
suite = unittest.TestSuite()
suite.addTest(WidgetTestCase('test
DefaultS
ize'))
suite.addTest(WidgetTestCase('test
R
esize'))
suite.addTest(WidgetTestCase('test
_default_s
ize'))
suite.addTest(WidgetTestCase('test
_r
esize'))
return suite
or even::
def suite():
tests = ['test
DefaultSize', 'testR
esize']
tests = ['test
_default_size', 'test_r
esize']
return unittest.TestSuite(map(WidgetTestCase, tests))
...
...
@@ -402,8 +402,8 @@ populating it with individual tests. For example, ::
suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase)
will create a test suite that will run ``WidgetTestCase.test
DefaultS
ize()`` and
``WidgetTestCase.test
R
esize``. :class:`TestLoader` uses the ``'test'`` method
will create a test suite that will run ``WidgetTestCase.test
_default_s
ize()`` and
``WidgetTestCase.test
_r
esize``. :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 determined by
...
...
@@ -610,8 +610,8 @@ Test cases
def suite():
suite = unittest.TestSuite()
suite.addTest(WidgetTestCase('test
DefaultS
ize'))
suite.addTest(WidgetTestCase('test
R
esize'))
suite.addTest(WidgetTestCase('test
_default_s
ize'))
suite.addTest(WidgetTestCase('test
_r
esize'))
return suite
Here, we create two instances of :class:`WidgetTestCase`, each of which runs a
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment