简体   繁体   中英

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() .

Robot Framework initializes the library twice:

  • 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.

If you set ROBOT_LIBRARY_SCOPE to GLOBAL , the library will be instantiated exactly once for a test run.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM