Reputation: 16971
Is there a way to define ROBOT_LIBRARY_SCOPE = 'GLOBAL' when creating tests dynamically ?
Currently I have to define ROBOT_LIBRARY_SCOPE in the class of my library, but I'd like to have it defined during the creation of the test case.
For example, I tried by adding to the imported Library - a class property:
suite.resource.imports.library('MyLib.py')
suite.resource.imports[-1].__class__.ROBOT_LIBRARY_SCOPE = 'GLOBAL'
# or with set attribute:
setattr(suite.resource.imports[-1].__class__, 'ROBOT_LIBRARY_SCOPE', 'GLOBAL')
And I also tried to add a class property to the created TestCase:
testCase = suite.tests.create('MyTest')
testCase.__class__.ROBOT_LIBRARY_SCOPE = 'GLOBAL'
# or with set attribute:
setattr(testCase.__class__, 'ROBOT_LIBRARY_SCOPE', 'GLOBAL')
But during test runtime, these class properties have no effect on the actual ROBOT_LIBRARY_SCOPE.
Upvotes: 1
Views: 3287
Reputation: 16971
I've suggested an implementation to set ROBOT_LIBRARY_SCOPE when importing custom libraries: https://github.com/manosnoam/robotframework/commit/98f62c4b29d399cdc16b39bb61e10f835c27c48e
Once my patch is merged, you'll be able to call for example:
suite.resource.imports.library('YourLib.py', scope='TEST SUITE')
Instead of setting ROBOT_LIBRARY_SCOPE in YourLib class:
ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
Upvotes: 1