运行 pylon webtests 时出现问题。 ImportError 和 TestController 未定义错误
我的目录结构如下: gnukhata/测试/功能。 在功能文件夹中,我有网络测试文件。以下是样本测试。
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,则显示以下错误,而不是 gnukhata.tests:
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
I have directory structure as follow:
gnukhata/tests/functional.
In functional folder I have web tests files. Following is the sample test.
from gnukhata.tests import *
class TestVendorController(TestController):
def test_index(self):
response = self.app.get(url(controller='vendor', action='index'))
After running this test file, gives following error:
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
Instead of gnukhata.tests if I write gnukhata then it shows the following error:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试我最简单的配置,让我知道它是否有效:
在 init.py 中:
Try my most simple configuration and let me know if it work:
In the init.py:
gnukhata/tests
目录中是否有__init__.py
?如果不是,则gnukhata.tests
不会被识别为模块,并且您无法从中导入。如果这样的文件确实存在,您可以在此处发布
gnukhata/tests/__init__.py
中的导入语句(如果有)吗?Is there an
__init__.py
ingnukhata/tests
directory? If not, thengnukhata.tests
is not recognized as a module and you can't import from it.If such file does exist, could you post here the import statements in
gnukhata/tests/__init__.py
if any?