Suppose I have this views function:<br><br>    res = DBSession.query(MyModel).first()<br>        return {&#39;result&#39;: res}<br><br>I want to use mock to write my unittest<br><br>    def setUp(self):<br>        # I am setting up a global patch (Don&#39;t Repeat Yourself)<br>
        self.p1 = patch(&#39;pyramid_app.views.MyModel&#39;)<br>        self.mk1 = self.p1.start()<br>        self.mk1.query.first.return_value = &#39;abc&#39;<br><br><br>    def test(self):<br>        r = my_view(Request)<br>
        self.assertEqual({&#39;result&#39;: &#39;abc&#39;}, r)<br><br><br>But the actual return is:<br><br>    AssertionError: { &#39;result&#39;: &#39;abc&#39;} != {&#39;result&#39;: &lt;MagicMock name=&#39;DBSession.query().first()&#39; id=&#39;185999084&#39;&gt;}<br>
<br>But I already set the return_value on the mock object, why do I still get the instance of the MagicMock and not the return_value? <br>I can, of course, access the `return_value`, but that is not a solution at all.<br>
<br><br>Thanks.<br><br>John<br>