the unittest mock library the following version of the test_some_func_with_params(test method verifies that the mock api_call(function was called with the correct parameter @patch('external_module api_call_with_param'def test_some_func_with_param(selfmock_api_call)sets up mock version of api_call mock_api_call return_value magicmock(status_code= response=json dumps({'age'' '})result some_func_with_param('phoebe'check result returned from some_func(is what was expected self assertequal(result response'{age"" "}''json result incorrect'verify that the mock_api_call was called with the correct params mock_api_call api_call_with_param assert_called_with('phoebe'if we wished to validate that it had only been called once we could use the assert_called_once_with(method mock and magicmock usage naming your mocks it can be useful to give your mocks name the name is used when the mock appears in test failure messages the name is also propagated to attributes or methods of the mockmock magicmock(name='foo'mock classes as well as mocking an individual method on class it is possible to mock whole class this is done by providing the patch(decorator with the name of the class to patch (with no named attribute/methodin this case the while class is replaced by magicmock object you must then specify how that class should behave