From: Steven D'Aprano on
I have two reported bugs in the bug tracker waiting on tests:

http://bugs.python.org/issue8128
http://bugs.python.org/issue4037

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.



--
Steven
From: Steven D'Aprano on
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:

http://docs.python.org/library/test.html

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():
test.test_support.run_unittest(UnicodeInterpolationTest)

if __name__ == "__main__":
test_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.)




--
Steven
From: exarkun on
On 06:52 am, steve(a)remove-this-cybersource.com.au wrote:
>
>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?

Take a careful look at the stack being reported. Then, think of a
better name than "test" for your file.

Jean-Paul
From: Steven D'Aprano on
On Sat, 20 Mar 2010 07:07:58 +0000, exarkun wrote:

>>What am I doing wrong?
>
> Take a careful look at the stack being reported. Then, think of a
> better name than "test" for your file.

Doh! *face-palm*

I was shadowing the test package with a long forgotten test module.


--
Steven
From: Mark Dickinson on
On Mar 20, 6:23 am, Steven D'Aprano <st...(a)REMOVE-THIS-
cybersource.com.au> wrote:
> I have two reported bugs in the bug tracker waiting on tests:
>
> http://bugs.python.org/issue8128http://bugs.python.org/issue4037
>
> Are there any guidelines for writing tests for the standard library and
> language?

Not that I can think of, beyond those you've already mentioned. I
mostly just copy the style of existing tests (though there are
definitely some test_*** files that aren't particularly well written).

For quick questions, you might get good answers by asking on the
#python-dev freenode IRC channel: a good few of the people interested
in testing (esp. Michael Foord, Ezio Melotti) can often be found
there.

--
Mark