79320566

Date: 2024-12-31 18:13:45
Score: 0.5
Natty:
Report link

Storage is a Protocol promising the method: account_list() We are calling the method to test (data_source.account_list) passing the mock. But before, we masquerade the mock (cast) to pretend it is compliant to the Storage protocol (which it is!)

It works fine and mypy does not complain


def test_account_list(data): mock_storage = mock.Mock() mock_storage.account_list.return_value = data

storage = cast(Storage, mock_storage)
result = data_source.account_list(storage)

mock_storage.account_list.assert_called_with()
assert result == data
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Jean-Marie Galliot