简体   繁体   English

测试 entry_point 贡献

[英]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.我正在编写一个 Python 模块,它指定了一组入口点,因此其他主机模块可以发现一项新功能。 I am following the setuptools approach specified at the official documentation .我遵循官方文档中指定的 setuptools 方法。

As an example, the snippet below shows a contribution through sample.contribution named hello-world which points to timmins.hello_world attribute.例如,下面的代码片段显示了一个名为 hello-world 的sample.contribution贡献,它指向 timmins.hello_world 属性。

[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.假设主机插件定义了一个类似下面的方法来加载 sample.contributions 扩展。

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.我想要做的是编写一个测试,以确保主机模块正确加载 entry_point。 At this moment, the only way of testing such entry_point loading is through building a wheel and pip-install it.目前,测试这种入口点加载的唯一方法是通过构建一个轮子并 pip-install 它。 Once installed, the entry_point can be loaded sucessfully.安装后,entry_point 可以成功加载。

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?所以,我的问题是......有没有办法在 setup.py(或 setup.cfg)中添加指定的 entry_points,以便在测试执行期间加载它们? That is, a test for the module that defines the entry_point that returns the contributions when calling the load_contributions method即对定义 entry_point 的模块的测试,该 entry_point 在调用load_contributions方法时返回贡献

Maybe using tox for executing a set of test commands is the right choice.也许使用tox来执行一组测试命令是正确的选择。 This approach installs the developed module into a virtual environment, and so its entry_points are loaded when invoking a command.这种方法将开发的模块安装到虚拟环境中,因此在调用命令时会加载其 entry_points。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM