我有如下的目錄結構: gnukhata/tests/functional。 在功能文件夾中我有Web測試文件。以下是樣品測試。運行pylon webtests的問題。 ImportError和TestController沒有定義errror
from gnukhata.tests import *
class TestVendorController(TestController):
def test_index(self):
response = self.app.get(url(controller='vendor', action='index'))
運行此測試文件後,給出以下錯誤:
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 651, in loadByNames
things.append(self.findByName(name))
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 460, in findByName
return filenameToModule(name)
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 98, in filenameToModule
return _importFromFile(fn)
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 117, in _importFromFile
module = imp.load_source(moduleName, fn, fd)
File "test_vendor.py", line 1, in <module>
from gnukhata.tests import *
exceptions.ImportError: No module named tests
相反gnukhata.tests的,如果我寫gnukhata話,就說明了以下錯誤:
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 651, in loadByNames
things.append(self.findByName(name))
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 460, in findByName
return filenameToModule(name)
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 98, in filenameToModule
return _importFromFile(fn)
File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 117, in _importFromFile
module = imp.load_source(moduleName, fn, fd)
File "test_vendor.py", line 3, in <module>
class TestVendorController(TestController):
exceptions.NameError: name 'TestController' is not defined
嘗試了上述解決方案,但沒有奏效out.So我寫test.py:從pylons.controllers 匯入pylons.templating進口render_mako WSGIController 作爲渲染 類的TestController(WSGIController): 高清__call __(自我,ENVIRON ,start_response): 返回WSGIController .__調用__(self,environ,start_response) 並將test.py文件保存在gnukhata/tests/functional目錄中。 使用trial運行測試不會給出任何錯誤。但是使用nosetest,它會給出錯誤:ImportError:沒有名爲pylons.controllers的模塊。 – ssonaldd 2011-05-12 12:49:43