[TIP] Multiplatform testing with nose

Michael Foord fuzzyman at voidspace.org.uk
Tue Feb 15 03:19:21 PST 2011


On 14/02/2011 21:53, Éric Araujo wrote:
> Le 14/02/2011 18:45, holger krekel a écrit :
>> Besides, it's always good to avoid code in __init__.py
>> files including imports.
> Could you elaborate on the reasons for that?  This has come up recently
> on another ML, python-dev I think, and the only rationale was use of
> setuptools namespace packages.

Seeing lots of code in an __init__.py always offends me, but I'm not 
sure I can fully rationalise it. :-)

I think the reason is that __init__.py serves the same purpose as class 
__init__. It is for initialisation, and doing a lot of "work" there is a 
bit of a design smell. If you *only* have an __init__.py then you 
shouldn't have a package, and if you have other modules in the package 
then the stuff you define in the __init__.py isn't namespaced properly 
(or in fact at all).

It means that classes defined in the __init__.py have a weird __module__ 
attribute, so as Holger said introspection becomes annoying.

Not everyone in the Python world agrees with this of course.

All the best,

Michael
> Regards
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python


-- 
http://www.voidspace.org.uk/

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html




More information about the testing-in-python mailing list