我正在学习 Python the Hard Way,我正在练习 47 - 自动化测试 ( http://learnpythonthehardway.org/book/ex47.html )
我正在使用 Python3(与书中使用的 Python 2.x 相比)并且我意识到 assert_equals(在书中使用)已被弃用。我正在使用 assertEqual。
我正在尝试构建一个测试用例,但由于某种原因,在 cmd 中使用 nosetests 时,出现错误:NameError: global name 'assertEqual' is not defined
这是代码:
from nose.tools import *
from ex47.game import Room
def test_room():
gold = Room("GoldRoom",
""" This room has gold in it you can grab. There's a
door to the north. """)
assertEqual(gold.name, "GoldRoom")
assertEqual(gold.paths, {})
def test_room_paths():
center = Room("Center", "Test room in the center.")
north = Room("North", "Test room in the north.")
south = Room("South", "Test room in the south.")
center.add_paths({'north': north, 'south': south})
assertEqual(center.go('north'), north)
assertEqual(center.go('south'), south)
def test_map():
start = Room("Start", "You can go west and down a hole")
west = Room("Trees", "There are trees here. You can go east.")
down = Room("Dungeon", "It's dark down here. You can go up.")
start.add_paths({'west': west, 'down': down})
west.add_paths({'east': start})
down.add_paths({'up': start})
assertEqual(start.go('west'), west)
assertEqual(start.go('west').go('east'), start)
assertEqual(start.go('down').go('up'), start)
我已经尝试在 GitHub 上搜索任何解决方案,但我不确定它为什么会给我 NameError 以及我将如何修复它。