热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在运行pytest测试之前安装python插件?

在使用pytest开始测试之前,我需要安装一个python插件,它是一个简单的python文件。我在setup.py中使用了entry_points。我的问题有点复杂,让

在使用 pytest 开始测试之前,我需要安装一个 python 插件,它是一个简单的 python 文件。我在 setup.py 中使用了 entry_points。我的问题有点复杂,让我们通过一个例子来解决这个问题,我们稍后再回到这个问题。

有两个包 - 一个是core,另一个是mypackage

核心提供了添加名为“ my.plugin ”的插件的功能。

核心封装逻辑

from importlib_metadata import entry_points
def plugin_method(some_data):
plugins = entry_points()['my.plugin']
loaded_plugins = []
for p in plugins:
loaded_plugins.apend(p.load())
#Does some processing on the data and decides which method to call from plugin
#call plugin method
return result

我的包逻辑

设置文件

setup(
...
entry_points={'my.plugin': 'plugin1= plugin1.logic'}
...
)

逻辑文件

def method1(method_data):
print('method1 called')
return 1
def method2(method_data):
print('method1 called')
return 2

主文件

def method_uses_plugin()
# create data
plugin_method(data)

该插件工作正常。:)



问题

我已经为method_uses_plugin方法编写了一个测试用例。如果我在我的机器上安装了pypackage,它工作正常,但如果安装没有完成,它会失败(在 jenkins 管道中)

我们通常不安装包来运行测试用例,因为测试用例应该直接使用源代码。

我们可能需要对 pytest 做一些事情来在 entry_points 中注册插件。我尝试了很多链接,但没有任何效果。

我的用例有点复杂,但可以在这里找到类似的问题


推荐阅读
author-avatar
童式恃
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有