[Distutils] programmatically adding entry points

Phillip J. Eby pje at telecommunity.com
Tue Apr 24 18:45:43 CEST 2007


At 05:27 PM 4/24/2007 +0200, Antoine Pitrou wrote:
>I've read the pkg_resources API (*) and I don't see any way of
>programmatically registering a (possibly temporary) entry-point. The
>only documented way to add entry points is to write setup scripts.
>But if I want to write unit tests for entry point-related behaviour, I
>don't want to run setup scripts in my unit tests. Is there a simple way
>to do this?

Write your code to separate the finding of entry points, from the 
*processing* of entry points.  Then pass in manually-created EntryPoint 
instances to test the processing routines.

Alternately, pass a mock WorkingSet to your routines that find entry 
points.  That is, write them like this:

    def some_routine(working_set=pkg_resources.working_set):
        for blah in working_set.iter_entry_points('whatever'):
            ...

And then just pass in a mock object for testing, that yields the EntryPoint 
instances you want to test.



More information about the Distutils-SIG mailing list