def test_using_context_manager(self): with mock.patch('work.os') as mocked_os: work_on() mocked_os.getcwd.assert_called_once()
def test_using_context_manager(self): with mock.patch('work.os.getcwd', return_value='testing') as mocked_os: assert work_on() == 'testing'
def test_using_return_value(self): with mock.patch('work.os.getcwd', return_value='patch_testing') as whatever: assert work_on() == 'patch_testing'
def test_using_decorator(self, mocked_os): work_on() mocked_os.getcwd.assert_called_once()
def test_using_return_value(self): """Note 'as' in the context manager is optional""" with mock.patch('work.os.getcwd', return_value='testing'): assert work_on() == 'testing'
def test_patch_context(self): with patch('work.os.getcwd', return_value='testing'): self.assertEqual(work_on(), 'testing')
def test_using_return_value(): with mock.patch('work.os.getcwd', return_value='testing'): assert work_on() == 'testing'