From 6406c7a5935e9fb9cd41af49f67d6200021b3574 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 29 Apr 2016 14:10:28 +0200 Subject: xmlrpc_test: Rename exception instance before working with it Python 3 unsets the exception variable at the end of an "except" block to prevent reference cycles and speed up garbage collection. Store the exception under a different name in order to use it later. Part of the work for https://fedorahosted.org/freeipa/ticket/4985 Reviewed-By: Martin Basti Reviewed-By: Petr Spacek --- ipatests/test_xmlrpc/xmlrpc_test.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'ipatests') diff --git a/ipatests/test_xmlrpc/xmlrpc_test.py b/ipatests/test_xmlrpc/xmlrpc_test.py index 330889341..4052ab918 100644 --- a/ipatests/test_xmlrpc/xmlrpc_test.py +++ b/ipatests/test_xmlrpc/xmlrpc_test.py @@ -330,14 +330,15 @@ class Declarative(XMLRPC_test): try: output = api.Command[cmd](*args, **options) except Exception as e: - pass + exception = e else: raise AssertionError( EXPECTED % (cmd, name, args, options, output) ) - if not isinstance(e, klass): + if not isinstance(exception, klass): raise AssertionError( - UNEXPECTED % (cmd, name, args, options, e.__class__.__name__, e) + UNEXPECTED % (cmd, name, args, options, + exception.__class__.__name__, exception) ) # FIXME: the XML-RPC transport doesn't allow us to return structured # information through the exception, so we can't test the kw on the @@ -345,21 +346,21 @@ class Declarative(XMLRPC_test): # transport, the exception is a free-form data structure (dict). # For now just compare the strings # pylint: disable=no-member - assert_deepequal(expected.strerror, e.strerror) + assert_deepequal(expected.strerror, exception.strerror) # pylint: enable=no-member def check_callable(self, nice, cmd, args, options, expected): name = expected.__class__.__name__ output = dict() - e = None + exception = None try: output = api.Command[cmd](*args, **options) except Exception as e: - pass - if not expected(e, output): + exception = e + if not expected(exception, output): raise AssertionError( UNEXPECTED % (cmd, name, args, options, - type(e).__name__, e) + type(exception).__name__, exception) ) def check_output(self, nice, cmd, args, options, expected, extra_check): -- cgit