How to force Robot Framework to initialize my custom library only once

3.5k Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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