[Tutor] unittest and private methods

Kent Johnson kent37 at tds.net
Sat Jan 21 13:13:12 CET 2006

lemeia wrote:
> kent wrote:
>>Rereading your mail another possibility comes to mind. It sounds like 
>>extractTo() is a general-purpose function that is used for a specific 
>>purpose by the module you are testing. Why not extract extractTo to a 
>>utility module? Then you can test it as much as you like in the unit 
>>tests for the utility and you can reuse it in other code if the need 
>>arises. Almost all of my projects have 'util' packages containing 
>>collections of miscellaneous useful stuff. The utils have their own unit 
>>tests and get included as needed in other modules and projects.
>> This makes sense to me and I hadn't thought of that in all honesty.
>> I
get so involved in object orientated design, I sometimes forget about
the convenience of a few general functions to "help out". Would I lose
my OO membership card though?

No, not at all, in fact you jeopardize your OO membership if you use it 
where it is not needed ;)

But seriously, one of the strengths of Python is that I can write OO 
code where appropriate, I can write procedural code when I don't need 
the extra power of classes, and I can write straight-line code when my 
needs are very simple, I can write in a functional style too. I can even 
mix the four styles in a single module if I want to.

So go ahead and make a utility module, or a public helper function at 
global scope in the same module as your class.


More information about the Tutor mailing list