def test_error(self):
"""Test raising exception if returncode is not zero."""
self.popen.returncode = 1
self.popen.communicate.return_value = ('Test', None)
with self.assertRaises(subprocess.CalledProcessError) as cm:
process.call('test', cwd='path', env={'NEW': '2'}, capture=False)
self.mock.Popen.assert_called_once_with(
'test', shell=True, cwd='path', env={'TEST': '1', 'NEW': '2'},
stdout=None, preexec_fn=os.setsid)
self.popen.communicate.assert_called_once_with()
self.mock.store_last_pid.assert_called_once_with(123)
self.assert_exact_calls(self.mock.kill_last_pid, [mock.call()] * 2)
self.assertEqual(1, cm.exception.returncode)
self.assertEqual('Test', cm.exception.output)
self.assertEqual('test', cm.exception.cmd)
self.mock.Thread.assert_called_once_with(
target=process.kill_when_timeout,
args=(self.popen, process.DEFAULT_TIMEOUT))
self.mock.Thread.return_value.start.assert_called_once_with()
评论列表
文章目录