support graphing mocked methods by ashanbrown · Pull Request #26 · mgedmin/objgraph
For posterity: here's what the various errors look like if I apply the patch to the tests, but run them against unmodified objgraph.py:
======================================================================
ERROR: test_short_repr_mocked_instance_method (__main__.StringRepresentationTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests.py", line 319, in test_short_repr_mocked_instance_method
self.assertRegex(objgraph._short_repr(my_mock.my_method), '<MagicMock')
File "/home/mg/src/objgraph/objgraph.py", line 873, in _short_repr
return obj.im_func.__name__ + ' (bound)'
File "/usr/lib/python2.7/dist-packages/mock/mock.py", line 718, in __getattr__
raise AttributeError(name)
AttributeError: __name__
======================================================================
ERROR: test_short_repr_mocked_instance_method_bound (__main__.StringRepresentationTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests.py", line 331, in test_short_repr_mocked_instance_method_bound
self.assertRegex(objgraph._short_repr(obj.my_method), '<Mock')
File "/home/mg/src/objgraph/objgraph.py", line 873, in _short_repr
return obj.im_func.__name__ + ' (bound)'
File "/usr/lib/python2.7/dist-packages/mock/mock.py", line 718, in __getattr__
raise AttributeError(name)
AttributeError: __name__
======================================================================
ERROR: test_short_repr_mocked_instance_method_bound_with_mocked_name (__main__.StringRepresentationTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests.py", line 351, in test_short_repr_mocked_instance_method_bound_with_mocked_name
self.assertRegex(objgraph._short_repr(obj.my_method), '<Mock')
File "/usr/lib/python2.7/unittest/case.py", line 999, in assertRegexpMatches
if not expected_regexp.search(text):
TypeError: expected string or buffer
----------------------------------------------------------------------