我有一个功能:
def function_to_test(df, filename):
df = process_df(df, arg1, arg2, arg3)
df.to_csv(filename, index=False)
我想在保存到文件之前模拟to_csv函数来检查数据帧对象是否已正确处理。我知道我想修补#34; to_csv"但我不知道如何获得它被调用的对象?
def test_function(self):
input_df = pd.DataFrame(... some df )
expected_result = pd.DataFrame(... some df )
with mock.patch("pandas.core.frame.DataFrame.to_csv"):
function_to_test(input_df, "dummy_filename")
# assert expected_result == processed_df