Jython v2.5 RobotFramework v2.7.5 Log4j v1.2.16
I have a Jython script as a listener that logs the variables
dictionary but it is not pretty-printed by pprint module as it does with attributes
dictionary.
I am using BuiltIn().get_variables() function to get the variables dictionary as:
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))
but this is the output in the logs:
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}
As you observe, and is stated in the docs (albeit ambiguously), BuiltIn().get_variables()
does not return a dictionary, but a dictionary-like object - to pretty-print you will have to get a dictionary from it:
dict(BuiltIn().get_variables().items())