[Distutils] testing with eggs

Phillip J. Eby pje at telecommunity.com
Sat Aug 20 01:45:14 CEST 2005


At 06:00 PM 8/19/2005 -0500, Ian Bicking wrote:
>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 kind of confused.  Maybe what you want is to create dummy Distribution 
objects and add them to a WorkingSet, then use the WorkingSet's APIs in 
your tests (such as iter_entry_points, require(), etc.).  It's not entirely 
clear to me what it is that you're testing, so I'm not sure.

In setuptools.tests.test_resources there's a simple Metadata class that's 
used to create dummy distributions that nonetheless have metadata; you 
could use something like that to create a dummy Distribution.

A WorkingSet is a collection of active Distributions, and it has methods 
like require(), iter_entry_points(), and so on.  There is a default global 
WorkingSet that's used for pkg_resources API, but you can create your own 
instances for testing purposes, and manipulating it won't affect 
sys.path.  The default working set has a listener subscribed to it that 
activates distributions on sys.path, but if you just create a WorkingSet 
for yourself it won't have this link.  The "api_tests.txt" file 
demonstrates some WorkingSet APIs, and "pkg_resources.txt" has complete 
reference docs for its methods.


>At first I tried adding fake_packages to sys.path; didn't work at all.

Because the subdirectories' names don't end in .egg; if they did and you 
just used EGG-INFO instead of .egg-info, it would work.


>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/

 From what little I can tell about what you're trying to do, I think you 
should just create dummy Distribution objects and add them a test-only 
WorkingSet, and not bother having anything in the filesystem, unless you're 
testing code that also does stuff with the filesystem.  In which case, you 
could just use pkg_resources' code to find and introspect packages, though, 
so as I said, I'm not sure what it is exactly you're testing.  :)



More information about the Distutils-SIG mailing list