[TIP] Guidelines for where to put tests & how to package them

C. Titus Brown ctb at msu.edu
Sat Feb 27 11:28:48 PST 2010


On Fri, Feb 26, 2010 at 08:29:16PM +0000, Michael Foord wrote:
> On 26/02/2010 20:12, Olemis Lang wrote:
>> On Fri, Feb 26, 2010 at 3:00 PM, Michael Foord
>> <fuzzyman at voidspace.org.uk>  wrote:
>>    
>>> On 26/02/2010 19:52, Olemis Lang wrote:
>>>      
>>>>        
>>>>> Probably Tarek and I need to discuss how
>>>>> the setup.py test command should work for distutils2. It should support
>>>>> non-unittest tests as well (I guess?) so specifying a unittest suite is
>>>>> not
>>>>> necessarily ideal.
>>>>>          
>>>> Well, unittest invokes `suite` callable by default
>>>>        
>>> Where does unittest invoke suite callable by default?
>>>
>>>      
>> That's what somebody told me when I was back in the school [1]_ (now
>> I'm an old man that forgets things ;o)
>>
>> {{{
>> For the ease of running tests, as we will see later, it is a good idea
>> to provide in each test module a 'callable' object that returns a
>> pre-built test suite:
>>
>>         def suite():
>>             suite = unittest.TestSuite()
>>             suite.addTest(WidgetTestCase("testDefaultSize"))
>>             suite.addTest(WidgetTestCase("testResize"))
>>             return suite
>> }}}
>>
>> .. [1] Python Unit Testing Framework
>>           (http://pyunit.sourceforge.net/pyunit.html)
>>    
>
> Right, that section of the documentation is unhelpful (and is still in  
> the unittest documentation until I get around to revamping it - which  
> includes removing that section).

Ahh, the ol' "I didn't write that section of the manual, and it's wrong
anyway" argument!  I like it.

> [ ... ] For modules loaded with a TestLoader the load_tests function  
> is better. For executing suites directly you can *now* do:
>
>     python -m unittest package.module.suitename
>
> This doesn't work with suite creating callables or with unittest in  
> Python 2.6 - it either requires 2.7 or unittest2.

OK, should we codify this as a convention that people SHOULD use?

> As doing "python -m unittest modulename" uses the load_test function to  
> create the suite (if this function is defined in the module) I see no  
> need to support 'get_suite' as callable. Further discussion with Tarek  
> required though.

Hmh, I'll have to try that out.

Tarek is a rather busy man, so let's bring him something that makes sense to US
and then he can tell us why it's wrong or incomplete. ;)

Seriously, he's managing the whole thing (multiple PEPs, documentation, etc.)
so I'd like to do our best to hash this out here before bringing it to
distutils.

Maybe I'm naive.

cheers,
--titus
-- 
C. Titus Brown, ctb at msu.edu



More information about the testing-in-python mailing list