On Thu, Mar 25, 2010 at 3:52 PM, Ingy dot Net <[email protected]> wrote:
> On Wed, Mar 24, 2010 at 3:06 PM, Gary Bernhardt <[email protected]>
> wrote:

>> - "del"ing local variables at the end of a function doesn't do
>> anything; it just destroyed the local reference, which would've been
>> destroyed when the function returned anyway.
>
> Actually it does do something in this case. When I ran the command:
>
>      >>> y(globals())
>
> inside pyplay, it showed the 'command' variable, which is an internal detail
> that the user doesn't need to know about. I get your point in general
> though.

I was referring to the "del"s in the (unused) init_readline_TODO
function. The "command" variable you del at the very end of the file
will indeed show up in the module's globals because the "if" is at
global scope. What you really want is to define a main() function
above the if with all that code in it, then just say:

if __name__ == '__main__':
    main()

This will do exactly what you want and never pollute the global
namespace. (I should've included this in my original feedback but it
slipped by. :)

> OK, about the testing. I fixed all your findings in just a few minutes but
> then spent the rest of the night trying to figure out python testing. I
> wanted to make it so that the tests would run with `make test`. I have a
> tiny Makefile that proxies targets to setup.py, so that would also be
> `python setup.py test`.
>
> It drove me to fits, and I would love some pointers here.
>
> You can see how I did it, but it's not particularly pretty. I didn't even
> use unittest or py.test or nose yet. Just an assert. I couldn't figure out
> how to invoke the framework tests from setup.py. And adding the 'test'
> command to setup.py took a lot of code. Thought it would be zero or one
> lines. :)

I've never bothered with the "python setup.py test" stuff, but it
seems like there should be some easier way to make it work. Sorry; I'm
no help there.

However, if you just make your "tests" directory a package (i.e.,
create a file tests/__init__.py), and name your test functions
test_whatever (or your test classes TestWhatever), then you can just
run nosetests at the root and it'll do the right thing. It traverses
the packages it can see, collecting anything that looks like a test,
then runs them all.

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

Reply via email to