对于某些人来说,几乎可以肯定这里有一些简单的要点。我已经使用 Python 大约一个星期了,当我尝试在我的单元测试中调用一个函数来构建文本夹具时,出现了 NameError: global name '_build_response' is not defined。对此我摸不着头脑,代码片段如下所示:
class HttpTestCase(unittest.TestCase):
def _build_response():
#build and returns some text fixtures
def test_http_get(self):
response = _build_response()
我对继承或作用域的理解是否遗漏了什么,或者是否有更令人尴尬的事情?任何指点表示赞赏。
请您参考如下方法:
class HttpTestCase(unittest.TestCase):
def _build_response(self):
# build and returns some text fixtures
pass
def test_http_get(self):
response = self._build_response()
_build_response 是HttpTestCase 类的一个方法
