[Distutils] testing with eggs
Ian Bicking
ianb at colorstudy.com
Sat Aug 20 01:00:05 CEST 2005
Just thought I'd pass this along, since it took me a little while to
figure it out. Maybe this can go in docs somewhere, but I'm not sure where.
So, I'm writing some code that uses egg plugins, and thus I need testing
eggs. These need to be path-independent (since the checkouts might live
anywhere), with no setup commands (you shouldn't have to install the
testing version of the eggs to run the tests), and the eggs should be
available only when you are running the tests (no global installation).
I'm using py.test, so I add a conftest.py file which is loaded before
any tests are imported. It's important all this is done before
pkg_resources is imported (maybe there are methods in pkg_resources that
can fix things after it was imported, but pkg_resources uses sys.path
when it is imported, so if you adjust the path later then pkg_resources
won't notice it).
Anyway, here's the code I use:
import os
import sys
import glob
here = os.path.dirname(__file__)
base = os.path.dirname(here)
fake_packages = os.path.join(here, 'fake_packages')
for egg_info_dir in glob.glob('%s/*/*.egg-info' % fake_packages):
sys.path.append(os.path.dirname(egg_info_dir))
At first I tried adding fake_packages to sys.path; didn't work at all.
But if I do site.addsitedir(fake_packages) then it would work. But this
requires an .egg-link file in fake_packages, and that file has to have
an absolute path (it can't be relative), but fake_packages could be
anywhere. So in the end, I just need to add all the necessary paths;
this means I can't test the case when --multi-version is used to install
an egg, but I guess I won't worry about that.
If you are curious about the base setup, I've checked in a minimal file
layout of the whole thing into
http://svn.pythonpaste.org/Paste/Deploy/trunk/
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Distutils-SIG
mailing list