[Python] How can I use side_effect to assert different values/parameter calls to the function...

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    In my code, I call a function two times in two different code paths. This is the function res = database_persist(self.session, SourceNames.SOMETHING, self.date, all_data, **params).

    In my unit test, I mock out the above function using:

    mock_database_persist = mocker.patch("admin.bootstrap.grouping.database_persist")


    I want to test that the first call to the function is

    assert mock_database_persist.assert_called_with(1, 2, 3, 4)


    And the second call to the function is

    assert mock_database_persist.assert_called_with(5, 6, 7, 8)


    Is there a way to assert each call to the function with different values/parameters?

    Continue reading...

Compartilhe esta Página