如何强制 Robot Framework 只初始化我的自定义库一次
How to force Robot Framework to initialize my custom library only once
我在 Python 中创建了一个自定义库,__init__
模块中的一个函数是 self.create_new_folder()
。
Robot Framework 初始化库两次:
一旦进入套件设置(我没有自己初始化库,
机器人自动完成)。
第二次初始化库是在调用自定义库中的第一个自定义关键字时,测试失败,因为文件夹已经创建
我可以检查文件夹是否已经存在,但我想知道是否有办法强制 Robot 只初始化库一次。
如果您将 ROBOT_LIBRARY_SCOPE
设置为 GLOBAL
,该库将为测试 运行.
恰好实例化一次
来自文档:
GLOBAL - Only one instance is created during the whole test execution
and it is shared by all test cases and test suites. Libraries created
from modules are always global.
示例:
class ExampleLibrary:
ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
见http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-library-scope
我在 Python 中创建了一个自定义库,__init__
模块中的一个函数是 self.create_new_folder()
。
Robot Framework 初始化库两次:
一旦进入套件设置(我没有自己初始化库, 机器人自动完成)。
第二次初始化库是在调用自定义库中的第一个自定义关键字时,测试失败,因为文件夹已经创建
我可以检查文件夹是否已经存在,但我想知道是否有办法强制 Robot 只初始化库一次。
如果您将 ROBOT_LIBRARY_SCOPE
设置为 GLOBAL
,该库将为测试 运行.
来自文档:
GLOBAL - Only one instance is created during the whole test execution and it is shared by all test cases and test suites. Libraries created from modules are always global.
示例:
class ExampleLibrary:
ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
见http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-library-scope