[New-bugs-announce] [issue11468] Improve unittest basic example in the doc

Ezio Melotti report at bugs.python.org
Fri Mar 11 19:15:42 CET 2011

New submission from Ezio Melotti <ezio.melotti at 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):

    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):

if __name__ == '__main__':

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

assignee: docs at python
components: Documentation
keywords: easy
messages: 130598
nosy: docs at 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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list