google-code-export / pymox

Automatically exported from code.google.com/p/pymox
0 stars 0 forks source link

mox fails with python 2.7.2rc1 #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by zul...@gmail.com on 2 Jun 2011 at 7:35

GoogleCodeExporter commented 9 years ago
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.

Original comment by soren@linux2go.dk on 2 Jun 2011 at 9:01

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

Original comment by daniel.h...@googlemail.com on 3 Jun 2011 at 4:52

GoogleCodeExporter commented 9 years ago
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.

Original comment by soren@linux2go.dk on 6 Jun 2011 at 8:34

GoogleCodeExporter commented 9 years ago
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.

Original comment by soren@linux2go.dk on 6 Jun 2011 at 9:12

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed with r63.  Thanks for the patch.

Original comment by stev...@google.com on 6 Jun 2011 at 6:44