def run_script(file_path):
    process = subprocess.Popen(['myscript', -M, file_path], stdout=
        subprocess.PIPE)
output, err = process.communicate()
return process.returncode

@mock.patch('subprocess.Popen')
def test_run_script(self, mock_subproc_popen):
    process_mock = mock.Mock()
attrs = {'communicate.return_value': ('output', 'error')}
process_mock.configure_mock(**attrs)
mock_subproc_popen.return_value = process_mock
Насмешка над вызовом подпроцесса в Python