Issue
New to unittest package.
I'm trying to verify the DataFrame returned by a function through the following code. Even though I hardcoded the inputs of assert_frame_equal
to be equal (pd.DataFrame([0,0,0,0])
), the unittest still fails. Anyone would like to explain why it happens?
import unittest
from pandas.util.testing import assert_frame_equal
class TestSplitWeight(unittest.TestCase):
def test_allZero(self):
#splitWeight(pd.DataFrame([0,0,0,0]),10)
self.assert_frame_equal(pd.DataFrame([0,0,0,0]),pd.DataFrame([0,0,0,0]))
suite = unittest.TestLoader().loadTestsFromTestCase(TestSplitWeight)
unittest.TextTestRunner(verbosity=2).run(suite)
Error: AttributeError: 'TestSplitWeight' object has no attribute 'assert_frame_equal'
Solution
assert_frame_equal()
comes from the pandas.testing
package, not from the unittest.TestCase
class. Replace:
self.assert_frame_equal(pd.DataFrame([0,0,0,0]),pd.DataFrame([0,0,0,0]))
with:
assert_frame_equal(pd.DataFrame([0,0,0,0]), pd.DataFrame([0,0,0,0]))
When you had self.assert_frame_equal
, it tried to find assert_frame_equal
attribute on the unittest.TestCase
instance, and, since there is not assert_frame_equal
attribute or method exposed on an unittest.TestCase
class, it raised an AttributeError
.
Answered By - alecxe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.