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

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    unittest.mock objects 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:

    with self.assertRaises(AssertionError):
    mock_function.assert_called_with(arguments_I_want_to_test)


    This works but clutters the code if I have several such calls I want to make.

    Related:


    Continue reading...

Compartilhe esta Página