unittest.mock

Writing a fake by hand is often clearest. When you only need "something that returns X and remembers how it was called", the standard library has unittest.mock.

A Mock() accepts any call and any attribute. Set return_value or side_effect to control what it gives back. Afterwards, ask it what happened: mock.call_count, mock.assert_called_once_with(...).

side_effect can be an exception, which makes it easy to test the error path: "what does my code do when the network fails?"

You will also see patch, which swaps a name inside a module for the length of a test:

with patch("shop.send_email") as fake_send:
    place_order(...)
fake_send.assert_called_once()

One trap: a mock accepts any attribute, so a misspelled check like mock.called_once_with(...) just returns another mock and never fails. Use the assert_ methods, which Python guards against common typos.

Run it, then make the second call to notify use a different user.