[Kimchi-devel] [project-kimchi] [PATCH] Bug Fix: Get correct exception info when run unittest on Python2.6

Sheldon shaohef at linux.vnet.ibm.com
Thu Jan 16 05:14:04 UTC 2014


On 07/09/2013 02:51 AM, Adam Litke wrote:
> On Thu, Jul 04, 2013 at 05:50:06PM +0800, caobbu at linux.vnet.ibm.com wrote:
>> From: Bing Bu Cao <mars at linux.vnet.ibm.com>
>>
>> When running unittest on SLES(python2.6), found a problem:
>> If an exception occurs in body of 'with' statement, the 'exc_value' is a str
>> not a exception object, 'raise firstException' will raise a TypeError.
>> In this case, we will not get info of the first exception.
>>
>> This is a bug on Python 2.6:
>> http://bugs.python.org/issue7853
>>
>> Reference:
>> http://docs.python.org/2.7/library/stdtypes.html#context-manager-types
>>
>> Signed-off-by: Bing Bu Cao <mars at linux.vnet.ibm.com>
>> ---
>>   tests/utils.py |   15 ++++-----------
>>   1 files changed, 4 insertions(+), 11 deletions(-)
>>
>> diff --git a/tests/utils.py b/tests/utils.py
>> index debccfb..11c8bf4 100644
>> --- a/tests/utils.py
>> +++ b/tests/utils.py
>> @@ -128,21 +128,14 @@ class RollbackContext(object):
>>           return self
>>
>>       def __exit__(self, exc_type, exc_value, traceback):
>> -        firstException = exc_value
>> -
>>           for undo, args, kwargs in self._finally:
>>               try:
>>                   undo(*args, **kwargs)
>>               except Exception as e:
>> -                # keep the earliest exception info
>> -                if not firstException:
>> -                    firstException = e
>> -                    # keep the original traceback info
>> -                    traceback = sys.exc_info()[2]
>> -
>> -        # re-raise the earliest exception
>> -        if firstException is not None:
>> -            raise firstException, None, traceback
> I don't think the proper solution is to delete the ability to raise the
> previous exception.  To workaround the python bug you could just check
> the type of exc_value and only raise if it's an Exception.  If it's a
> string you can just log it.
not only string but also int.

should we still consider this patch.
or we will not give up to support RollbackContext on some distros?

$ ./run_tests.sh test_utils
FE
======================================================================
ERROR: test_path_permission (test_utils.searchPermissionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/user/kimchi/tests/test_utils.py", line 145, in 
test_path_permission
break
File "/home/user/kimchi/tests/utils.py", line 177, in __exit__
raise firstException, None, traceback
TypeError: exceptions must be old-style classes or derived from 
BaseException, not int

>
>> +                traceback = sys.exc_info()[2]
>> +                raise e, None, traceback
>> +
>> +        return False if exc_value is not None else True
>>
>>       def defer(self, func, *args, **kwargs):
>>           self._finally.append((func, args, kwargs))
>> -- 
>> 1.7.7.6
>>
>> -- 
>> project-kimchi mailing list <project-kimchi at googlegroups.com>
>> https://groups.google.com/forum/#!forum/project-kimchi
>> ---
>> You received this message because you are subscribed to the Google Groups "project-kimchi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to project-kimchi+unsubscribe at googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list