我正在编写一个针对我的Python 2.7方法的单元测试用例。
在我的测试方法中,有一个调用方法,它接受一个具有字符串键和panadas数据帧作为该键值的字典。
我想为这个方法编写一个交互测试,以检查它是否使用正确的字典调用了内部方法
def MethodUnderTest(self):
#some code here
externalMethod(dictionary_of_string_dataframe)
#some code here
在单元测试中,我编写了以下的断言来测试这个交互:
mock_externalClass.externalMethod.assert_called_once_with(dictionary_of_string_dataframe)
我创建了 dictionary_of_string_dataframe,方法与实际方法完全相同。事实上,我复制了测试代码中执行此操作的帮助方法,只是为了确保两个字典是相同的。在调试Python控制台上的测试方法时,我甚至打印了两个字典,两者看起来完全相同。
而且我使用 @patch 装饰器对外部类进行了修补,一切都很顺利。
问题是,在上述断言语句中,我得到了以下错误:
mock_externalClass.externalMethod.assert_called_once_with(dictionary_of_string_dataframe)
File "C:\Python27\lib\site-packages\mock\mock.py", line 948, in assert_called_once_with
return self.assert_called_with(*args, **kwargs)
File "C:\Python27\lib\site-packages\mock\mock.py", line 935, in assert_called_with
if expected != actual:
File "C:\Python27\lib\site-packages\mock\mock.py", line 2200, in __ne__
return not self.__eq__(other)
File "C:\Python27\lib\site-packages\mock\mock.py", line 2196, in __eq__
return (other_args, other_kwargs) == (self_args, self_kwargs)
File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 953, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我对ValueError进行了搜索,但没有得到太多帮助。有人可以告诉我这里发生了什么吗?
我确实查看了以下问题,但那并没有帮助: