I have a method - run_script()
- I would like to test. Specifically, I want to test that a call to subprocess.Popen
occurs. It would be even better to test that subprocess.Popen
is called with certain parameters. When I run the test however I get TypeError: 'tuple' object is not callable
.
How can I test my method to ensure that subprocess
is actually being called using mocks?
@mock.patch("subprocess.Popen")
def run_script(file_path):
process = subprocess.Popen(["myscript", -M, file_path], stdout=subprocess.PIPE)
output, err = process.communicate()
return process.returncode
def test_run_script(self, mock_subproc_popen):
mock_subproc_popen.return_value = mock.Mock(
communicate=("ouput", "error"), returncode=0
)
am.account_manager("path")
self.assertTrue(mock_subproc_popen.called)