测试入口点贡献 [英] Testing a entry_point contribution
问题描述
我正在编写一个 Python 模块,它指定了一组入口点,以便其他主机模块可以发现新的功能.我正在遵循 官方文档.
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.
举个例子,下面的代码片段展示了一个名为 hello-world 的 sample.contribution
贡献,它指向 timmins.hello_world 属性.
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
假设宿主插件定义了一个类似下面的方法来加载 sample.contributions 扩展.
Let's suppose the host plugin defines a method like the following for loading sample.contributions extensions.
def load_contributions():
...
我想做的是编写一个测试,确保entry_point 被主机模块正确加载.目前,测试此类入口点加载的唯一方法是构建一个轮子并通过 pip 安装它.一旦安装,entry_point 就可以成功加载了.
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.
所以,我的问题是......有没有办法在 setup.py(或 setup.cfg)中添加指定的 entry_points,以便在测试执行期间加载它们?即对定义entry_point的模块进行测试,该入口点在调用load_contributions
方法
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
推荐答案
也许使用 tox 用于执行一组测试命令是正确的选择.这种方法将开发的模块安装到虚拟环境中,因此在调用命令时会加载其入口点.
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.
这篇关于测试入口点贡献的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!