On Mon, Mar 29, 2010 at 8:34 PM, Ingy dot Net <[email protected]> wrote:
>
> Thanks. Actually it does pollute the global namespace a bit, with the key

Ahh, this is a different issue. Before, we were talking about not
polluting, but what you're really talking about here is total control.
For that, you want to define __all__ in your module. It's a list of
strings; only those strings will be visible from the outside.

However, I've found that, in general, anything useful to the module
might be useful to the outside, and you probably should just expose
it. Why not just expose main, for example? What if I want to wrap
PyPlay, doing some sort of magic and then calling your main function?
Seems reasonable to me!

The only time I use __all__ is when I'm writing a top-level API module
and simplicity is very important – in my Expecter Gadget library, for
example.

> I want to learn unittest since it is core. Now I can tell people to run
> 'python setup.py test' or simply 'make test' and it will always do the right
> thing.

Make? We don't use that around here! ;) (Well, except for building
Python itself...) I still suspect that there's a much easier way to
make "setup.py test" work, although I'm not motivated to find out what
it is. My projects always have a "runtests.py" file (e.g., [1]) that
invokes nose, because I like to configure things like test naming.

> PS. It turned out the setup.py only ran the first test, if I had multiple
> tests. That is because unittest calls sys.exit!! That seems evil to me. I
> was overjoyed to find out I could work around this with even more evil. I
> added this to my setup.py:
>         def exit(code):
>             pass
>         sys.exit = exit
> :-D

OH GOD KILL IT WITH FIRE!

[1] http://bitbucket.org/garybernhardt/dingus/src/tip/runtests.py

-- 
Gary
http://blog.extracheese.org

Reply via email to