[Python-Dev] setUpClass and setUpModule in unittest

Holger Krekel holger.krekel at gmail.com
Tue Feb 9 20:14:13 CET 2010


On Tue, Feb 9, 2010 at 7:29 PM, Olemis Lang <olemis at gmail.com> wrote:
> On Tue, Feb 9, 2010 at 11:42 AM, Michael Foord
> <fuzzyman at voidspace.org.uk> wrote:
>> Hello all,
>>
>> Several
>> authors of other Python testing frameworks spoke up *against* them, but
>> several *users* of test frameworks spoke up in favour of them. ;-)
>>
>
> +1 for having something like that included in unittest

hey Olemis, aren't you a test tool author as well? :)

>> I'm pretty sure I can introduce setUpClass and setUpModule without breaking
>> compatibility with existing unittest extensions or backwards compatibility
>> issues
>
> Is it possible to use the names `BeforeClass` and `AfterClass` (just
> to be make it look similar to JUnit naming conventions ;o) ?
>
>> - with the possible exception of test sorting. Where you have a class
>> level setUp (for example creating a database connection) you don't want the
>> tearDown executed a *long* time after the setUp. In the presence of class or
>> module level setUp /tearDown (but only if they are used) I would expect test
>> sorting to only sort within the class or module [1]. I will introduce the
>> setUp and tearDown as new 'tests' - so failures are reported separately,
>
> Perhaps I am missing something, but could you please mention what will
> happen if a failure is raised inside class-level `tearDown` ?
>
>> and
>> all tests in the class / module will have an explicit skip in the event of a
>> setUp failure.
>>

I think reporting tests as skipped when the setup failed is a bad idea.
Out of several years of practise with skips and large test suites (and
talking/experiencing many users :) i recommend to reserve skips for
platform/dependency/environment mismatches. A Setup Error should
just error or fail all the tests in its scope.

cheers,
holger


More information about the Python-Dev mailing list