New submission from Ezio Melotti <ezio.melo...@gmail.com>:

The current example[0] uses assertTrue(element in self.seq) but it would be 
better to use assertIn instead.  The whole example could be changed to 
something simpler that uses only the assertTrue/assertEqual/assertRaises 
methods correctly, e.g.:

import unittest

class TestStringMethods(unittest.TestCase):

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # check that s.split fails when the separator is not a string
        with self.assertRaises(TypeError):
            s.split(2)

if __name__ == '__main__':
    unittest.main()

[0]: http://docs.python.org/py3k/library/unittest.html#basic-example

----------
assignee: docs@python
components: Documentation
keywords: easy
messages: 130598
nosy: docs@python, eric.araujo, ezio.melotti, michael.foord, ncoghlan, 
rhettinger
priority: low
severity: normal
stage: needs patch
status: open
title: Improve unittest basic example in the doc
type: feature request
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11468>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to