def test_getlogin_bad(self): with mock.patch('os.getenv') as os_getenv: with mock.patch('os.getlogin') as os_getlogin: os_getenv.side_effect = [None, None, 'bar'] os_getlogin.side_effect = OSError( '[Errno 22] Invalid argument') self.assertEqual(cmd._getlogin(), 'bar') os_getlogin.assert_called_once_with() self.assertEqual(os_getenv.call_count, 3)
def test_getlogin(self): with mock.patch('os.getlogin') as os_getlogin: os_getlogin.return_value = 'foo' self.assertEqual(cmd._getlogin(), 'foo')