Python patch decorator spilled into other methods

I understand that when you use the patch decorator on unit test (I use the nose framework), the scope of this patch decorator is the scope of the test case. Here's the problem:

@patch('a')
@patch('b')
@patch('b')
def test_add_stuff(self, mock_a, mock_b, mock_c):
    url = '/path/blah/blah'
    assert_true(stuff)
    # Now those three patch decorators should be "done"


def test_delete_stuff(self):
    url = '/another_path/not_important'
    assert_true(something)

In my second test case, test_delete_stuff, I added a print statement to the actual code to debug the error that was selected. It turns out that one of the function calls inside the controller’s action that get through the URL returns a MagicMock object! This is mock_b from the previous test case.

If I just change the order of the two test cases, nothing changes. If I comment on one that has decorators, my second test case passes.

Additional Information: There are no patch handlers in the class that contain these instance methods.

?

- -

, , . , , .

, GET app.get, , MagicMock ?

+4

All Articles