0

I have this function

def my_function(param1, param2):
    ...
    my_other_function(param1, param2, <something else>)
    ...

I want to test that my_other_function is being called with param1 and param2, and I don't care about the rest

I wrote a test like this

@mock.patch('mymodule.my_other_function')
def test_my_other_function_is_called(my_other_function_mock):

   my_function('foo', 'bar')
   my_other_function_mock.assert_called_once_with('foo', 'bar', ?????)

Is there any value I can pass to the assert_called_once_with method (or any of the "sister" method from MagicMock, so that the assertion passes? Or do I have to manually get the calls list, and check each of the parameters with which the function was called?

vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
  • 1
    Possible duplicate of [How to check for mock calls with wildcards?](http://stackoverflow.com/questions/22184642/how-to-check-for-mock-calls-with-wildcards) – anthony sottile Mar 05 '17 at 23:44

1 Answers1

2

In the docs https://docs.python.org/3/library/unittest.mock.html#any is said that you can use unittest.mock.ANY:

@mock.patch('mymodule.my_other_function')
def test_my_other_function_is_called(my_other_function_mock):

   my_function('foo', 'bar')
   my_other_function_mock.assert_called_once_with('foo', 'bar', ANY)
Alexey Ruzin
  • 967
  • 8
  • 17