Suppose this is the code
def move(*args, **kwargs):
try:
shutil.move(source, destination)
except Exception as e:
raise e
and in my tests.py
@patch.object(shutil, 'move')
def test_move_catch_exception(self, mock_rmtree):
''' Tests moving a target hits exception. '''
mock_rmtree.side_effect = Exception('abc')
self.assertRaises(Exception, move,
self.src_f, self.src_f, **self.kwargs)
It said this
File "unittests.py", line 84, in test_move_catch_exception
self.src_f, self.src_f, **self.kwargs)
AssertionError: Exception not raised
If I assert on mock_rmtree
it will pass. How can I assert on the caller (in this case, the function move
)?
As aquavitae pointed out, the primary reasons was copy-paste error, and also I was asserting a tuple in the beginning. Always asseert with the right return type...