[TIP] coverage.py and subprocesses

Geoff Bache geoff.bache at gmail.com
Mon Aug 23 12:41:40 PDT 2010


Hi all,

I've just been trying to convert my coverage testing to use the new
suggested methods for coverage 3.3, i.e. to get code to be called on
interpreter startup so I don't have to add coverage hooks into my
source code everywhere a new process starts. As described here:

http://nedbatchelder.com/code/coverage/subprocess.html

I'm however having trouble getting it to work. I rejected the .pth
solution because it requires me to write files in global locations
which scares me. So I modified sitecustomize.py, adding in the two
lines

    import coverage
    coverage.process_startup()

which doesn't work either out of the box. I think this is because my
installation of coverage is found by PYTHONPATH rather than being in
the default site-packages. What happens is that the code above (i.e.
sitecustomize.py) gets called before the setuptools magic has done its
thing and added the coverage egg to sys.path, meaning the coverage
module isn't found. It does work on another machine where I have the
rights to install coverage in the default location.

I can of course work around this by explicitly adding the egg
directory to PYTHONPATH but it feels a bit wrong. Is there some better
way to handle this?

I also wonder if anyone knows if Python will ever develop a nicer way
of calling code on interpreter startup. See Ned Batchelder's blog post

http://nedbatchelder.com/blog/201001/running_code_at_python_startup.html

which I sympathise with somewhat...

Regards,
Geoff



More information about the testing-in-python mailing list