动态创建测试时,是否可以定义ROBOT_LIBRARY_SCOPE ='GLOBAL'?
目前,我必须define ROBOT_LIBRARY_SCOPE in the class of my library,但是我想在创建测试用例时对其进行定义。
例如,我尝试通过在导入的库中添加类属性:
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')
我还尝试将类属性添加到创建的TestCase中:
testCase = suite.tests.create('MyTest')
testCase.__class__.ROBOT_LIBRARY_SCOPE = 'GLOBAL'
# or with set attribute:
setattr(testCase.__class__, 'ROBOT_LIBRARY_SCOPE', 'GLOBAL')
但是在测试运行时,这些类属性对实际的ROBOT_LIBRARY_SCOPE无效。
答案 0 :(得分:0)
我建议一种实现,在导入自定义库时设置ROBOT_LIBRARY_SCOPE: https://github.com/manosnoam/robotframework/commit/98f62c4b29d399cdc16b39bb61e10f835c27c48e
一旦我的补丁被合并,您就可以拨打电话:
suite.resource.imports.library('YourLib.py', scope='TEST SUITE')
不是在YourLib类中设置ROBOT_LIBRARY_SCOPE:
ROBOT_LIBRARY_SCOPE ='测试套件'