Export to GitHub

pymox - issue #51

mox.Mox.CreateMock() chokes if dir() and getattr() do not agree


Posted on Nov 9, 2012 by Helpful Kangaroo

What steps will reproduce the problem?

Attempt to use mox.Mox.CreateMock() on an object where dir(obj) lists an attribute but getattr(obj, attr_name) raises AttributeError.

What is the expected output? What do you see instead?

For example, in Python 2.7 type lists abstractmethods as an attribute while getattr(type, 'abstractmethods') fails:

>>> mox.Mox().CreateMock(type) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mox.py", line 284, in CreateMock new_mock = MockObject(class_to_mock, attrs=attrs) File "mox.py", line 603, in init attr = getattr(class_to_mock, method) AttributeError: abstractmethods >>>

A similar situation can arise when using slots:

>>> class ac(object): slots = 'a', ... >>> mox.Mox().CreateMock(ac()) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mox.py", line 284, in CreateMock new_mock = MockObject(class_to_mock, attrs=attrs) File "mox.py", line 603, in init attr = getattr(class_to_mock, method) AttributeError: a >>>

What version of the product are you using? On what operating system?

The latest version of mox from SVN, with Python 2.7.3rc2, built for 32-bit Linux.

I have attached a patch to ignore such bogus attributes, with two test cases.

Attachments

Comment #1

Posted on Nov 12, 2012 by Massive Wombat

Fixed in http://code.google.com/p/pymox/source/detail?r=74

Status: Fixed

Labels:
Type-Defect Priority-Medium