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

Michael Foord fuzzyman at voidspace.org.uk
Fri Feb 26 12:49:40 PST 2010


On 26/02/2010 20:46, Olemis Lang wrote:
> On Fri, Feb 26, 2010 at 3:29 PM, Michael Foord
> <fuzzyman at voidspace.org.uk>  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).
>>
>>      
> {{{
>    
>>>> from unittest import TestCase as TC, main
>>>> class MyTC(TC):
>>>>          
> ...   def test_fail(self):
> ...     self.fail()
> ...
>    
>>>> def suite():
>>>>          
> ...     from unittest import TestSuite as TS
> ...     suite = TS()
> ...     suite.addTest(MyTC("test_fail"))
> ...     return suite
> ...
>    
>>>> main()
>>>>          
> F
> ======================================================================
> FAIL: test_fail (__main__.MyTC)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>    File "<stdin>", line 3, in test_fail
> AssertionError
>
> ----------------------------------------------------------------------
> Ran 1 test in 0.000s
> }}}
>
> so it works, and that happens since sooo long that ...
>    

Ha. Try the same experiment without defining the suite function and I 
think you will find that still works... (main introspects the __main__ 
module and runs tests on all test cases it finds - in the example above 
it isn't calling your suite function).

Michael

> If that's gonna change , some people might cry (not /me, I use
> `test_suite` ;o) so ...
>
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.





More information about the testing-in-python mailing list