[TIP] coverage.py and subprocesses
geoff.bache at gmail.com
Mon Aug 23 12:41:40 PDT 2010
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:
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
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
which I sympathise with somewhat...
More information about the testing-in-python