python3 mock.assert_called_once_with on changing list

时间:2016-04-21 22:47:49

标签: list python-3.x testing mocking

Hello guys,

class MyClass:
    def foo(self):
        items = ["A"]

        self.bar(items)

        items.append("B")

        print(items)

    def bar(self, items):
        pass


class MyTest(unittest.TestCase):
    def test_MyClass(self):
        with patch.object(MyClass, "bar") as mock_bar:
            obj = MyClass()

            obj.foo()

            mock_bar.assert_called_once_with(["A", "B"])

This test succeeds but it shouldn't. mock_bar was called with a list of only one item, not a list of two items. I had expected the assert_called_once_with does a deep test (checking the content of the items).

Is there any way to know, when the mock / method was called, how the actual content looked like?

Thanks!

0 个答案:

没有答案