Skip to content Skip to sidebar Skip to footer

Python-mock: 'self' Parameter Lacking Default Value

This used to work with python mock version 1.0.1, but started failing after I upgraded to mock version 1.3.0. I am running python version 2.7.10 on Mac OS X Yosemite 10.10.5. I red

Solution 1:

Ommit spec_set (and spec) on instance method mock of Outer.MyClass.doStuff. The self will not be captured/asserted by assert_called_once_with and your test will pass.

    @patch.object(Outer, "MyClass", autospec=True,
          return_value=Mock(spec_set=Outer.MyClass, 
                            doStuff=Mock()))

Post a Comment for "Python-mock: 'self' Parameter Lacking Default Value"