如何包含已安装pip包中的Variables文件



我目前在包含Robot Framework时遇到问题"变量";包含在pythonpip包中的文件。我可以成功地将文件作为";Library";,但不是";变量";。我之所以将变量存储在pip包中,是因为这个包是私人维护的,并在各种项目中使用。

文件的示例内容,包括我需要从Robot Framework访问的变量和函数:"package_file.py">


VARIABLE_ABC = "important constant here"

def my_function(arg1, arg2)
return 0

我可以创建一个伪文件,它只从包文件中导入所有变量,并且它的路径是已知且一致的。我认为这是一种变通方法,而不是理想的解决方案:

"my_variables_file_copy.py">

from my_module.package_file import *

请参阅下面我的一个.robot文件中的示例语法,以更好地解释正在发生的事情:

*** Settings ***
Documentation    Description of this file
# This brings in functions, but not variables
Library          my_module.package_file
# This doesn't work
Variables        my_module.package_file
# This does work, but is not ideal
Variables        my_variables_file_copy.py
# This would also work but is not ideal and could be change depending on the installation
Variables         path/to/installed/pip/package/my_module/package_file.py

关于如何处理这种情况,有什么建议吗?

最近在Robot Framework 5.0 中添加了对此的支持

https://github.com/robotframework/robotframework/blob/master/doc/releasenotes/rf-5.0.rst#variable-文件可以作为模块导入

相关内容

最新更新