How can I verify a Python method was called with parameters including a DataFrames?
I'm using MagicMock to verify that a method was called with specific arguments:
ClassToMock.method_to_mock = MagicMock(name='method_to_mock')
ClassToMock.method_that_creates_data_frame_and_passes_to_mocking_method()
ClassToMock.method_to_mock.assert_called_with('test_parameter_value', self.get_test_data_frame())
Where self.get_test_data_frame()
is a pre-defined DataFrame that is the expected result of the call.
When I print out the DataFrame passed to the mocking method and the the test DataFrame I can see that they look equal when printed:
but the test output does not think they are equal:
File "C:\python3.6\lib\unittest\mock.py", line 812, in assert_called_with if expected != actual: File "C:\python3.6\lib\unittest\mock.py", line 2055, in eq return (other_args, other_kwargs) == (self_args, self_kwargs) File "C:\python3.6\lib\site-packages\pandas\core\generic.py", line 1330, in nonzero f"The truth value of a {type(self).name} is ambiguous. " ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
From reading other issues I think it is because the MagicMock tries to call == but Pandas require .equals() to check for equality. Does anyone know of an alternative approach?
from Recent Questions - Stack Overflow https://ift.tt/35UTd2O
https://ift.tt/34K2qLC
Comments
Post a Comment