[英]How to force Robot Framework to initialize my custom library only once
I have created a custom library in Python that one of the functions in the __init__
module is self.create_new_folder()
. 我已经在Python中创建了一个自定义库,
__init__
模块中的功能之一是self.create_new_folder()
。
Robot Framework initializes the library twice: Robot Framework将库初始化两次:
Once in the suite setup (I do not initialize the library myself, robot does it automatically). 一旦进入套件设置(我自己没有初始化库,机器人会自动完成)。
The second time it initializes the library is when it calls the first custom keyword from the custom library, and the test fails because the folder is already created. 第二次初始化库是从定制库调用第一个定制关键字时,测试已失败,因为已经创建了文件夹。
I can check if the folder already exists but I would like to know if there is a way to force Robot to initialize the library only once. 我可以检查该文件夹是否已经存在,但是我想知道是否有一种方法可以强制Robot只初始化一次库。
If you set ROBOT_LIBRARY_SCOPE
to GLOBAL
, the library will be instantiated exactly once for a test run. 如果将
ROBOT_LIBRARY_SCOPE
设置为GLOBAL
,则该库将被完全实例化一次以进行测试运行。
From the documentation: 从文档中:
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.
从模块创建的库始终是全局的。
Example: 例:
class ExampleLibrary:
ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
See http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-library-scope 参见http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-library-scope
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.