小编aur*_*uro的帖子

Python NameError:未定义全局名称"assertEqual"

我正在努力学习Python,我正在练习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}) …
Run Code Online (Sandbox Code Playgroud)

python nameerror

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

nameerror ×1

python ×1