Skip to content
Advertisement

Tag: python-unittest.mock

How to employ a MagicMock spec_set or spec on a method?

I am trying to use a method as a spec_set on a MagicMock. https://stackoverflow.com/a/25323517/11163122 provides a nice example of an unexpected call signature resulting in an Exception. Unfortunately, I can’t get it to work out for a method. How can I get the below code snippet to error out, given the calls don’t match the spec? I am using Python

Python – How can I assert a mock object was not called with specific arguments?

I realize unittest.mock objects now have an assert_not_called method available, but what I’m looking for is an assert_not_called_with. Is there anything like that? I looked on Google and didn’t see anything, and when I tried just using mock_function.assert_not_called_with(…) it raised an AttributeError, meaning the function does not exist with that name. My current solution This works but clutters the code

Advertisement