[Python-Dev] Proposed unittest changes

Steve Purcell steve at pythonconsulting.com
Thu Apr 17 17:39:16 CEST 2008

Great that you're taking this on, Michael!

On 17 Apr 2008, at 16:59, Michael Foord wrote:

>> If you're looking for useful features, Google has a set of extensions
>> to unittest.py that I find useful:
>> - module-level setUp and tearDown
> So when a suite is made from a module the setUp should be called  
> before the first test and tearDown after the last. I can look at that.

Note that suites are just clumps of tests, and test runners can choose  
to run tests in any order, which might complicate the above.

In any case, I'd advise against per-module setUp/tearDown because it  
breaks the fundamental rule that any instance of TestCase can be  
safely run in isolation, secure in the knowledge that it will set  
itself up and tear itself down as required.  There are usually  
(always?) superior alternatives to module-level setUp, so I wouldn't  
suggest encouraging it by providing a sanctioned mechanism.

Also, I'd note that assert_() or similar may still be needed: it is  
provided as a preferred alternative to the assert() built-in because  
the latter stops working if you run Python with the -O switch, which  
might be a reasonable thing to do with a test suite.

Aside from these points, everything else looks great to me.  Better  
"diff-style" output for assertEquals of strings etc. has been lacking  
for ages, as well as collection-oriented assertions.


P.S. Hi all!

More information about the Python-Dev mailing list