Python单元测试设置功能'未定义'

mar*_*ers 1 python scope

对于某些人来说,这里几乎肯定有些简单 我已经使用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()
Run Code Online (Sandbox Code Playgroud)

我是否遗漏了对继承或范围界定的理解,或者是否有更令人尴尬的事情?任何指针赞赏.

San*_*4ez 7

class HttpTestCase(unittest.TestCase):   

  def _build_response(self):           
      # build and returns some text fixtures
      pass

  def test_http_get(self): 
      response = self._build_response()
Run Code Online (Sandbox Code Playgroud)

_build_response是一种HttpTestCase阶级方法