Python Unittest求助
写了一个类,做单元测试的时候碰到了一个很诡异的问题。
from unittest import TestCase
class Account():
def __init__(self, name, value = 0, subs = {}):
self.name = name
self.subs = subs
self.value = value
class AccountTest(TestCase):
def test_empty(self):
base = Account('test', 100)
self.assertEqual(base.name, 'test')
self.assertEqual(base.value, 100)
self.assertEqual(base.subs, {})
from unittest import TestCase
class Account():
def __init__(self, name, value = 0, subs = {}):
self.name = name
self.subs = subs
self.value = value
def add_account(self, son):
self.subs[son.name] = son
class AccountTest(TestCase):
def test_empty(self):
base = Account('test', 100)
self.assertEqual(base.name, 'test')
self.assertEqual(base.value, 100)
self.assertEqual(base.subs, {})
def test_add_account(self):
base = Account('test', 100)
father = Account('father')
father.add_account(base)
self.assertEqual(father.subs, {base.name: base})