Jython v2.5 RobotFramework v2.7.5 Log4j v1.2.16
我有一个Jython脚本作为listener记录了variables
字典,但pprint模块并没有像attributes
字典一样打印它。< / p>
我使用BuiltIn().get_variables()函数将变量字典作为:
def start_suite(self, name, attributes):
self.LOGGER.info('<<<start_suite>>>')
self.LOGGER.debug('variables @ start suite: %s' % pprint.pformat(BuiltIn().get_variables()))
self.LOGGER.debug('attributes @ start suite: %s' % pprint.pformat(attributes))
但这是日志中的输出:
2013-05-29 08:03:11,493 [51a618afdf08ff6296260098] DEBUG [NativeMethodAccessorImpl] - variables scoped at start suite: {'${outputdir}': u'/mypath/', '${outputfile}': 'NONE', '${reportfile}': 'NONE', '${none}': None, '${prevtestmessage}': '', '${suitemetadata}': {}, '${suitedocumentation}': '', '${\\n}': '\n', '${/}': '/', '${true}': True, '${:}': ':', '${suitesource}': u'/mypath/source', '${space}': ' ', u'${environment}': u'sit', '${suitename}': u'MySuite', '${debugfile}': 'NONE', '${null}': None, '${logfile}': 'NONE', '${prevteststatus}': '', '${tempdir}': u'/tmp', '${execdir}': u'mypath3', '${prevtestname}': '', '${false}': False, '@{empty}': (), '${empty}': ''}
2013-05-29 08:03:11,499 [51a618afdf08ff6296260098] DEBUG [NativeMethodAccessorImpl] - attributes @ start suite: {'doc': '',
'longname': u'BcvDocumentImageRequestTest',
'metadata': {},
'source': u'/robotRoot/MyTest',
'starttime': '20130529 08:03:11.224',
'suites': [u'MyTest', u'MyTest'],
'tests': [],
'totaltests': 2}
答案 0 :(得分:2)
正如你所观察到的,并且是stated in the docs(虽然含糊不清),BuiltIn().get_variables()
不会返回字典,而是类似字典的对象 - 要精美打印,你必须从中获取字典:
dict(BuiltIn().get_variables().items())