Python 在Robot框架中导入自定义测试库

Python 在Robot框架中导入自定义测试库,python,robotframework,Python,Robotframework,我正在为Python中的Robot Framework编写一个自定义测试库,我想这样导入它: Library CustomLibrary 我将包含源代码的文件夹放在PYTHONPATH上,但仍然收到错误:导入测试库“CustomLibrary”失败:导入错误:没有名为CustomLibrary的模块 CustomLibrary类在\uuuuu init\uuuuuuu.py文件中定义,如在AppiumLibrary中所示: from CustomLibrary.keywords

我正在为
Python
中的
Robot Framework
编写一个自定义测试库,我想这样导入它:

Library         CustomLibrary
我将包含源代码的文件夹放在
PYTHONPATH
上,但仍然收到错误:
导入测试库“CustomLibrary”失败:导入错误:没有名为CustomLibrary的模块

CustomLibrary
类在
\uuuuu init\uuuuuuu.py
文件中定义,如在
AppiumLibrary
中所示:

from CustomLibrary.keywords import *

class CustomLibrary(_CustomKeywords):
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

如何解决这个问题,以便在Robot框架中导入它?我想将类定义保存在init文件中。

您需要确保包含
CustomLibrary
的文件夹位于PYTHONPATH上

例如,以下工作符合我的预期:

  • 在/tmp中创建名为CustomLibrary的文件夹
  • 创建一个名为/tmp/CustomLibrary/\uuuu init\uuuuu.py的文件
  • 在/tmp/CustomLibrary/\uuuu init\uuuuuuuu.py中定义一个名为CustomLibrary的类
  • 在CustomLibrary类中定义一个方法
  • 使用
    library CustomLibrary
  • 将/tmp添加到PYTHONPATH并运行robot。例如,
    robot--pythonpath/tmp示例.robot

  • 您需要确保包含
    CustomLibrary
    的文件夹位于PYTHONPATH上

    例如,以下工作符合我的预期:

  • 在/tmp中创建名为CustomLibrary的文件夹
  • 创建一个名为/tmp/CustomLibrary/\uuuu init\uuuuu.py的文件
  • 在/tmp/CustomLibrary/\uuuu init\uuuuuuuu.py中定义一个名为CustomLibrary的类
  • 在CustomLibrary类中定义一个方法
  • 使用
    library CustomLibrary
  • 将/tmp添加到PYTHONPATH并运行robot。例如,
    robot--pythonpath/tmp示例.robot

  • 自定义库路径是什么?
    /Users//Desktop/Python/CustomLibrary/
    你看过这篇文章了吗?对我的所有软件包中都有一个
    \uuuu init\uuuu.py
    文件当你说“将包含源代码的文件夹放在PYTHONPATH上”时,你是什么意思?如果
    CustomLibrary
    是文件夹
    foo
    中的一个文件夹,您是将
    foo
    放在PYTHONPATh上,还是将
    foo/CustomLibrary
    放在PYTHONPATh上?CustomLibrary路径是什么?
    /Users//Desktop/Python/CustomLibrary/
    您查看过这篇文章了吗?对我的所有软件包中都有一个
    \uuuu init\uuuu.py
    文件当你说“将包含源代码的文件夹放在PYTHONPATH上”时,你是什么意思?如果
    CustomLibrary
    是文件夹
    foo
    中的一个文件夹,您是将
    foo
    放在PYTHONPATh上,还是将
    foo/CustomLibrary
    放在PYTHONPATh上?