[Python-Dev] Proposed unittest changes

Jean-Paul Calderone exarkun at divmod.com
Mon Jul 14 02:58:48 CEST 2008


On Sun, 13 Jul 2008 23:51:44 +0100, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>Ben Finney wrote:
>>Howdy Michael,
>>
>>I'm interested in the changes you're proposing for Python's 'unittest' 
>>module. I am (like, I suspect, many Python coders) maintaining my own set 
>>of extensions to the module across many projects, so I'd really like to see 
>>many of the improvements you discuss actually in the standard library.
>>
>>What assistance can I offer to help on this issue?
>>
>>
>I intend to start working on them in August, after I have finished my 
>current writing commitments.
>
>The full list of changes proposed (feel free to start - but ping me or the 
>list) and not shot down was something like:
>
>Documenting that the assert method names are to be preferred over the 
>'FailUnless' names (this stirred up some controversy this weekend so should 
>probably not happen).
>
>
>Adding the following new asserts:
>
>    assertIn    (member, container, msg=None)
>    assertNotIn     (member, container, msg=None)
>    assertIs     (first, second, msg=None)
>    assertNotIs   (first, second, msg=None)
>    assertRaisesWithMessage    (exc_class, message, callable, *args, 
>**keywargs)
>

Several of these are implemented in other libraries (Twisted, at least).
You might save some time by grabbing them and their unit tests, rather
than re-implementing them.  Twisted calls `assertIs´ `assertIdentical´,
by the way.

> [snip]
>
>Other suggestions that weren't controversial but I might not get to:
>
>    assertRaisesWithMessage taking a regex to match the error message
>

Actually, I remember that someone raised an object to this as being not
as flexible as some might want - an objection I agree with.  Perhaps that
was overruled, but I didn't want this to slip by as "not controversial".

>    expect methods that collect failures and report at the end of the test 
>(allowing an individual test method to raise several errors without 
>stopping)
>
>    assertIsInstance and assertIsSubclass
>

The former of these is also in Twisted already, if you want to copy it.

Jean-Paul


More information about the Python-Dev mailing list