test.py:
@pytest.mark.django_db
def test_b_called(mocker):
b = mocker.patch('app.service.b')
service.a('b')
assert b.called
service.py:
def a(type):
_actions[type]()
def b():
pass
_actions = { 'b': b }
My test will fail as my patch does not work as I expected. What am I doing wrong here? This definitely works if a calls b directly and not using that dictionary. I have tested for this. I know you can mock a dictionary with patch.dict but then how would I test that b was called?