0

Jython v2.5 RobotFramework v2.7.5 Log4j v1.2.16

我有一个 Jython 脚本作为记录字典的侦听variables器,但pprint模块不像attributes字典那样打印得很好。

我正在使用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}
4

1 回答 1

2

正如您所观察到的,并且在文档中有所说明(尽管含糊不清),BuiltIn().get_variables()它不会返回字典,而是返回类似字典的对象 - 要漂亮地打印,您必须从中获取字典:

dict(BuiltIn().get_variables().items())
于 2013-05-30T08:55:09.823 回答