def test_rm2(self, mock_os, mock_path): """ 注意 os 和 path 的顺序 :param mock_os: :param mock_path: :return: """ mock_path.isfile.return_value = False # test_mylib that the remove call was NOT called. self.assertFalse(mock_os.remove.called, "这个函数没被调用 Failed to not remove the file if not present.") # make the file 'exist' mock_path.isfile.return_value = True rm("any path") mock_os.remove.assert_called_with("any path")
def test_rm2(self, mock_os, mock_path): """ 注意 os 和 path 的顺序 :param mock_os: :param mock_path: :return: """ mock_path.isfile.return_value = False # test_mylib that the remove call was NOT called. self.assertFalse( mock_os.remove.called, "这个函数没被调用 Failed to not remove the file if not present.") # make the file 'exist' mock_path.isfile.return_value = True rm("any path") mock_os.remove.assert_called_with("any path")
def test_rm(self, mock_os): rm("any path") # 它以为删除了某目录 #pass #rm("any path") # test_mylib that rm called os.remove with the right parameters mock_os.remove.assert_called_with("any path") # 参数传入, 但其实什么都没发生
def test_rm(self): # remove the file rm(self.tmpfilepath) # test_mylib that it was actually removed self.assertFalse(os.path.isfile(self.tmpfilepath), "Failed to remove the file.")