Writing tests for the Python bug tracker

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Mar 20 07:52:08 CET 2010

On Sat, 20 Mar 2010 06:23:14 +0000, Steven D'Aprano wrote:

> Are there any guidelines for writing tests for the standard library and
> language? I've googled, but found nothing useful: lots of guidelines for
> writing tests, and of course I've read PEP 8, but I'm not sure if there
> are conventions for tests I'm missing.

I've found this:


and I've written a small test:

$ cat test_unicode_interpolation.py
# For testing http://bugs.python.org/issue8128

import test.test_support
import unittest

class K(unicode):
    def __str__(self): return "Surprise!"

class UnicodeInterpolationTest(unittest.TestCase):
    def test_interpolation(self):
        self.assertEquals(u'%s' % K('some text'), 'Surprise!')

def test_main():

if __name__ == "__main__":

but when I try running the test, I get an error:

$ python test_unicode_interpolation.py
Options: {'delimiter': None}
str of options.delimiter = None
repr of options.delimiter = None
len of options.delimiter
Traceback (most recent call last):
  File "test_unicode_interpolation.py", line 3, in <module>
    import test.test_support
  File "/home/steve/python/test.py", line 8, in <module>
    print "len of options.delimiter", len(options.delimiter)
TypeError: object of type 'NoneType' has no len()

What am I doing wrong?

(By the way, I'm expecting the unit test above to fail.)


More information about the Python-list mailing list