[Python-Dev] Single .py file contains submodule?

Kevin Butler kbutler@campuspipeline.com
Fri, 31 May 2002 15:03:37 -0600


M.-A. Lemburg wrote:
 > Kevin Butler wrote:
 > > from unittest.assertions import *
 >
> That's bad style (at least for modules which don't only include
> constants). Why would you want to enable this ?

:-)

- In general, if you provide a submodule, users can do 'from unittest import 
assertions' or 'import unittest.assertions as test' or some such. Just having 
a grundle of top-level symbols in a module is less convenient than appropriate 
grouping into submodules.

- The Style Guide suggests prefixing methods that are intended for use with 
'import *', and these functions are 'test*' or 'assert*'...

- For test code, I tend to be a bit more liberal with 'import *', because in 
general, test code is pretty clear about what it is exercising.

- The assertion methods are very independent of the other TestCase methods, 
and can be very useful for non-TestCase methods. This low coupling/high 
cohesion suggests organizing them together, but currently there's no 
convenient way to get at them separately. And since the methods really have 
little to do with an object instance, I find the 'self.assert*' construct 
distracting, although I like self.* in most cases.

kb