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

Michael Foord fuzzyman at voidspace.org.uk
Sat Feb 27 12:00:48 PST 2010


On 27/02/2010 19:48, C. Titus Brown wrote:
> On Sat, Feb 27, 2010 at 07:37:54PM +0000, Michael Foord wrote:
>    
>> On 27/02/2010 19:32, C. Titus Brown wrote:
>>      
>>> So where our goals differ is that you want to define a new convention
>>> going forward (2.7+, 3.3+) and I want to document some convention that's
>>> "good enough"&   backwards compatible to 2.4.
>>>        
>> I will strongly argue, and suspect Tarek will agree, that the
>> recommended practise for Python 2.4+ users is to use distutils2. That
>> way they can use the conventions that will just-work (tm) in future
>> versions of Python. distutils2 and unittest2 are both maintaining
>> compatibility with Python 2.4 specifically so they can be used in this
>> way.
>>      
> Humm, why isn't this style of test running:
>
>    % python -m somepackage.tests.run
>
> a good solution that removes the need for using distutils2 for 2.4+ users?
>    

Because it requires providing a run module that implements test 
collection and running, which is very dull code to write and easy to get 
wrong or fail to update as you add new tests.

The following is a lot simpler and ideally requires the programmer to 
write *no* extra code and can be run post-installation:

% unit2 discover # python 2.4-2.6
% python -m unittest discover # python 2.7+
[snip...]
> I don't like or really understand the unittest test running and reporting
> tools.  Maybe it's a problem that can be solved with documentation or
> just by LARTing myself.
>
> I'll go take a look.
>
>    

Ok. unittest running and reporting is not complex, or difficult to 
customize, once you understand the moving parts. Better documentation is 
certainly part of the problem. Changes to make unittest more extensible 
are the long term solution.

This may or may not help (loaders and runners anyway):

http://www.voidspace.org.uk/python/articles/introduction-to-unittest.shtml#loaders-runners-and-all-that-stuff

The TextTestRunner uses a _TextTestResult (silly underscore removed in 
recent versions). The runner uses the result which does the reporting.

Michael Foord


-- 
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