Export to GitHub

pymox - issue #35

mox fails with python 2.7.2rc1


Posted on Jun 2, 2011 by Massive Horse

While updating to python 2.7.2rc1 we got the following traceback:

File "/usr/lib/pymodules/python2.7/mox.py", line 256, in CreateMock new_mock = MockObject(class_to_mock, attrs=attrs) File "/usr/lib/pymodules/python2.7/mox.py", line 553, in init for method in dir(class_to_mock): TypeError: dir() must return a list, not MockMethod

Comment #1

Posted on Jun 2, 2011 by Helpful Camel

This reproduces the problem:

=== mymodule.py ===

class MyClass(object): pass

=== reproduce.py ===

import mox import mymodule

class Test(object): def init(self): self.mox = mox.Mox() self.mox.StubOutWithMock(mymodule, 'MyClass', use_mock_anything=True) self.mox.CreateMock(mymodule.MyClass)

Test()

I don't know if this is CPython changing its behaviour to be closer to spec and pymox depending on CPython implementation details. I'm hoping someone else can clear this up.

Comment #2

Posted on Jun 3, 2011 by Massive Dog

It might be worth keeping an eye on http://bugs.python.org/issue12248 (original issue filed here: https://bugs.launchpad.net/python/+bug/791221).

Comment #3

Posted on Jun 6, 2011 by Helpful Camel

Everyone weighing in on that bug on bugs.python.org seems to agree that the strict type checking should be done away with. However, the change itself (calling dir for old-style classes) seems like it's going to stay, so pymox will need fixing regardless. This is because pymox isn't just returning the wrong sort of list-like object, but rather a MockMethod.

Comment #4

Posted on Jun 6, 2011 by Helpful Camel

I'm applying this patch in Ubuntu to stop being blocked on this issue. If you choose a different approach to addressing this issue, I will of course follow suit.

Attachments

Comment #5

Posted on Jun 6, 2011 by Massive Wombat

Fixed with r63. Thanks for the patch.

Status: Fixed

Labels:
Type-Defect Priority-Medium