[Distutils] Testing with stubbed entry points?
Phillip J. Eby
pje at telecommunity.com
Wed Feb 22 17:09:08 CET 2006
At 12:26 PM 2/22/2006 +0200, Iwan Vosloo wrote:
>I'm trying to write tests for an egg which expects certain entry
>points to be supplied for an entry point group it is interested in.
>What is the easiest way (in testing code) to make a new entry point in
>some group in a test setup, and nuke it again in the test tearDown?
Well, there isn't a particularly easy way right now. You have to create a
Distribution with a dummy metadata containing entry_points.txt, or else you
have to subclass Distribution to create a mock that returns what you want
from the entry point methods. You then have to add that Distribution to a
WorkingSet instance, and you need to make your code use that WorkingSet
instead of the default working_set. One way you can do this is by having
some of your methods or functions take an argument that defaults to the
global working_set, but can be overridden by the test code.
If you want to take the dummy metadata route, see the setuptools test
modules, as they have a mock metadata class that you can give the text of
what metadata files the distribution will seem to have.
More information about the Distutils-SIG