[Tutor] Newbie & Unittest ...

Lie Ryan lie.1296 at gmail.com
Thu May 6 18:26:41 CEST 2010


On 05/06/10 10:37, Damon Timm wrote:
> Hi - am trying to write some unit tests for my little python project -
> I had been hard coding them when necessary here or there but I figured
> it was time to try and learn how to do it properly.
> <snip>
> This test works, however, it only runs as *one* test (which either
> fails or passes) and I want it to run as 12 different tests (three for
> each file type) and be able to see which key is failing for which file
> type.  I know I could write them all out individually but that seems
> unnecessary.

One way to do what you wanted is to harness python's dynamicity and
generate the methods by their names:

class TestFiles(unittest.TestCase):
    for methname, case in somedict:
        def test(self):
             ...
        __dict__[methname] = test



More information about the Tutor mailing list