Karellen Archives - Arcadiy Ivanov https://www.ivanov.biz/category/projects/karellen-general/ Fighting entropy one code line at a time Sun, 19 Jun 2022 19:53:18 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.4 https://www.ivanov.biz/wp-content/uploads/2023/02/cropped-Arcadiy_2141-scaled-e1677291990351-32x32.jpg Karellen Archives - Arcadiy Ivanov https://www.ivanov.biz/category/projects/karellen-general/ 32 32 84149164 How to spy on Mock-wrapped method calls in Python https://www.ivanov.biz/2016/howto-spy-with-python-mock/ https://www.ivanov.biz/2016/howto-spy-with-python-mock/#respond Fri, 01 Apr 2016 22:40:13 +0000 https://www.ivanov.biz/?p=431 You have a class whose API you want to verify: class Class_A(object): def method_X(self): self.method_Y() def method_Y(self): pass You write the following test fully expecting it to pass. Alas, the method_Y assertion fails. def test_class_a(self): obj = Class_A() mock = MagicMock(spec_set=obj, wraps=obj) mock.method_X() mock.method_Y.assert_called_once_with() This is because the Python Unittest Mock, while wrapping mock.method_X(), Mock … Continue reading "How to spy on Mock-wrapped method calls in Python"

The post How to spy on Mock-wrapped method calls in Python appeared first on Arcadiy Ivanov.

]]>
https://www.ivanov.biz/2016/howto-spy-with-python-mock/feed/ 0 431