Export to GitHub

pymox - issue #54

StubOutWithMock on a MockAnything sometimes succeeds, sometimes fails.


Posted on Feb 15, 2013 by Happy Lion

What steps will reproduce the problem?

  1. Create a source file mox_restub.py, with the following contents:

import mox

class MyClass(object):

def MyFunction():
    pass

m=mox.Mox()

print MyClass.MyFunction # <unbound method MyClass.MyFunction>

m.StubOutWithMock(MyClass, 'MyFunction')

print MyClass.MyFunction # <MockAnything instance at 139942970002032>

m.StubOutWithMock(MyClass, 'MyFunction')

print MyClass.MyFunction # <MockAnything instance at 139942970064208>

m.StubOutWithMock(MyClass, 'MyFunction') # TypeError: Cannot Mock a MockAnything! Did you # remember to call UnsetStubs in your previous # test?

  1. run python ./mox_restub.py

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

I expect an exception to be thrown at the second call to StubOutWithMock, since MyClass.MyFunction is already a MockAnything that has not been unset with UnsetStubs.

Instead, the second call to StubOutWithMock silently succeeds, but the third call fails.


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

mox: python-mox 0.5.3-1ubuntu5 os: Ubuntu 12.04.1 LTS

Status: New

Labels:
Type-Defect Priority-Medium