diff --git a/src/utils/python.py b/src/utils/python.py index bf898299d..d5665cc33 100644 --- a/src/utils/python.py +++ b/src/utils/python.py @@ -159,7 +159,15 @@ def collect_extra_debug_data(): frame_locals = frame.f_locals for inspected in ('self', 'cls'): if inspected in frame_locals: - for attr_name in dir(frame_locals[inspected]): + try: + attribute_names = dir(frame_locals[inspected]) + except Exception: # For Python 2 and Pypy + try: + attribute_names = list( + frame_locals[inspected].__dict__) + except Exception: + attribute_names = [] + for attr_name in attribute_names: try: v = getattr(frame_locals[inspected], attr_name) except Exception: diff --git a/test/test_utils.py b/test/test_utils.py index 48cb02d51..0407345f8 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1179,9 +1179,9 @@ class UtilsPythonTest(SupyTestCase): def test_dict(self): class Foo: def __hasattr__(self, n): - raise Exception() + raise Exception(n) def __getattr__(self, n): - raise Exception() + raise Exception(n) def f(): self = Foo() @@ -1199,7 +1199,7 @@ class UtilsPythonTest(SupyTestCase): class Foo: __slots__ = ('bar',) def __hasattr__(self, n): - raise Exception() + raise Exception(n) def __getattr__(self, n): raise Exception(n)