使用Python实现类对象相等

使用Python实现类对象相等,python,Python,输出: import unittest from EarnClass import Employee class TestGive(unittest.TestCase): def setUp(self): self.data = Employee('x', 'y', 'z') def test_give_default(self): #"""xxxx""" self.assertEqual(self.dane, 'x y z'

输出:

import unittest
from EarnClass import Employee
class TestGive(unittest.TestCase):

    def setUp(self):
        self.data = Employee('x', 'y', 'z')

    def test_give_default(self):
        #"""xxxx"""

        self.assertEqual(self.dane, 'x y z')
AssertionError:!='xyz'

'x y z'
属于
str
类型,不能等同于
员工
实例(可能不是
str
类型,除非您继承了它)。

测试的输出是不言自明的。您的问题是什么?如何将类参数与此对象相等?您需要向我们解释为什么字符串
'x y z'
应该类似于
Employee
的实例。也许您可以更新该问题,使其包含
Employee
类的相关部分。`def\uuuu init\uuuu(self,name,lastname,EarnYear):self.name=name self.lastname=lastname self.EarnYear=EarnYear可能重复:
AssertionError:<EarnClass.Employee object at 0x027EA290> != 'x y z'