Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
75 views
in Technique[技术] by (71.8m points)

python - Testing a entry_point contribution

I am writing a Python module that specifies a set of entry_points, so other host modules can discover a new piece of functionality. I am following the setuptools approach specified at the official documentation.

As an example, the snippet below shows a contribution through sample.contribution named hello-world which points to timmins.hello_world attribute.

[options.entry_points]
sample.contribution =
    hello-world = timmins:hello_world

Let's suppose the host plugin defines a method like the following for loading sample.contributions extensions.

def load_contributions():
   ...

What I want to do is to write a test that ensures the entry_point is properly loaded by the host module. At this moment, the only way of testing such entry_point loading is through building a wheel and pip-install it. Once installed, the entry_point can be loaded sucessfully.

So, my question is ... Is there any way of adding the specified entry_points at setup.py (or setup.cfg) so they can be loaded during the tests execution? That is, a test for the module that defines the entry_point that returns the contributions when calling the load_contributions method

question from:https://stackoverflow.com/questions/65846516/testing-a-entry-point-contribution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe using tox for executing a set of test commands is the right choice. This approach installs the developed module into a virtual environment, and so its entry_points are loaded when invoking a command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...