我写了一个单元测试,它应该比较从我的方法返回的Column对象。我在测试中创建一个,然后从我的班级中获得一个。我的测试代码如下所示:
def test_getting_correct_sa_object_from_column(self):
table = self.database.get_table_by_name('ESEventlogMain')
column = table.get_column_by_name('eventdata')
sa_column = sqlalchemy.Column('eventdata', sqlalchemy.Integer, primary_key=False)
self.assertEqual(sa_column, column.get_sa_object())
我班上的方法就是这样:
def get_sa_object(self):
if self.type == 'int':
sa_type = sqlalchemy.Integer
elif self.type == 'varchar':
sa_type = sqlalchemy.String(self.length)
return sqlalchemy.Column(self.name, sa_type, primary_key=self.is_primary_key)
当我运行测试时,它输出失败:
Failure
Traceback (most recent call last):
File "C:\Users\tames.mctigue\PycharmProjects\db_setup_wizard\tests.py", line 107, in test_getting_correct_sa_object_from_column
self.assertEqual(sa_column, column.get_sa_object())
AssertionError: Column('eventdata', Integer(), table=None) != Column('eventdata', Integer(), table=None)
AssertionError显示的内容看起来像是相同的数据,所以我一直在寻找什么。除了“assertEqual”之外,我应该使用不同的比较吗?
答案 0 :(得分:0)
尝试使用直接列,例如:
def test_getting_correct_sa_object_from_column(self):
table = self.database.get_table_by_name('ESEventlogMain')
column = table.get_column_by_name('eventdata')
sa_column = table.eventdata # <- Change this column
self.assertEqual(sa_column, column.get_sa_object())