Unit-testing single function with large number of different inputs

Edvard Majakari edvard+news at majakari.net
Wed Feb 18 09:39:46 EST 2004


Peter Otten <__peter__ at web.de> writes:

Hm, one more question about this:
>
> import unittest, os
>
> # shared implementation
> class Base(unittest.TestCase):
>     def __init__(self, filename):
>         unittest.TestCase.__init__(self)
>         self.filename = filename
>
> # some pointless tests
> class Good1(Base):
>     def runTest(self):
>         self.assertEqual(self.filename, self.filename.lower())
>
> class Good2(Base):
>     def runTest(self):
>         self.assertEqual(self.filename.endswith(".py"), True)
>
> class Bad(Base):
>     def runTest(self):
>         self.assertEqual(self.filename.endswith(".pyc"), True)

now, running tests with the -v flag I don't see the neat docstrings I've
used everywhere, but class instance strings (which is not that neat).
Then again, it doesn't really matter, but still..

Doing

 # shared implementation
 class Base(unittest.TestCase):
     def __init__(self, filename):
         unittest.TestCase.__init__(self)
         self.filename = filename
>        self.runTest.__doc__ = "fiddling with file %s" self.filename

 # some pointless tests
 class Good1(Base):
     def runTest(self):
         self.assertEqual(self.filename, self.filename.lower())

doesn't work, because doc strings are read-only (which is good in general)

Now, it really doesn't matter a lot, I just thought it would be neater and
I'm also quite sure Python is able to do this, if I only knew how.

-- 
# Edvard Majakari		Software Engineer
# PGP PUBLIC KEY available    	Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";



More information about the Python-list mailing list