jeudi 29 novembre 2018

Python mock returns a MagicMock object instead of a specified result value

I want to mock test this function:

def foo():
  client = boto3.client(some_args)
  return client.func_A(other_args)

So I mock boto3 in my test:

def test_foo():
  with patch('boto3') as mock_boto3:
    mock_boto3.return_value.client.return_value.func_A.return_value = 'test_val'
    foo()

The proiblem with this is that func_A returns a MagicMock object instead of the specified return value. What am I doing wrong?

<MagicMock name='boto3.client().func_A()' id='140131668642896'>

Aucun commentaire:

Enregistrer un commentaire