lundi 4 juillet 2016

Getting return value problems with unittest patch() in python

I am trying to use mock.patch to unittest my code, however I am getting a strange result. This is the important part of the code:

@mock.patch('benchmark.scenarios.networking.feature.ssh')
@mock.patch('benchmark.scenarios.networking.feature.subprocess.call')
def test_run_for_success(self, mock_subprocess, mock_ssh):
    mock_ssh.SSH().execute.return_value = (0, '100', '')
    mock_subprocess.call().return_value = 'mocked!'

    result = {}
    self.feature.run(result)

When I run ssh in my code, I get the returned value: (0, '100', ''), good! However, when I run subprocess.call() I get as returned value:

<MagicMock name='subprocess.call()' id='139806699670096'>

What am I doing wrong? I would like to get 'mocked!' as returned value.

Aucun commentaire:

Enregistrer un commentaire