所以,下面是两个类。当我在它们上运行 unittest ( python -m unittest -v unit_test
,此代码保存为“unit_test.py”) 时,第二类中的测试被执行,但不是第一类中的测试。任何线索可能出了什么问题?
重要的一切似乎都是相同的,但 Python 只是从def setUp(self):
第一类的行跳到第二类。(因为它跳过那里,我认为发布hac.process_lines()
该类中显示的代码无关紧要。)非常感谢任何帮助。谢谢!
class TestClient(unittest.TestCase):
"""
Tests the central clause of the program
"""
def setUp(self):
self.store = {}
self.example_1 = ['set foo bar', 'get foo', 'set baz bat', 'list',
'delete foo', 'get baz']
self.example_2 = ['auth test testpw', 'set foo bar', 'get foo', 'set \
baz bat', 'list', 'delete foo', 'get baz']
def correct_dictionary_v1(self):
self.store = hac.process_lines(self.example_1)
self.assertEqual(self.store, {'baz': 'bat'})
def correct_dictionary_v2(self):
self.store = hac.process_lines(self.example_2)
self.assertEqual(self.store, {'baz': 'bat'})
class TestGetValue(unittest.TestCase):
"""
Tests the 'get' command function
"""
def setUp(self):
self.store = {}
self.key = 'key'
self.value = 'value'
def test_good_input(self):
self.store = {'key': 'value'}
self.assertEqual('value', hac.get_value(self.store, self.key))
def test_missing_key(self):
self.store = {}
self.assertEqual(1, hac.get_value(self.store, self.key))