运行 pylon webtests 时出现问题。 ImportError 和 TestController 未定义错误

发布于 2024-11-06 10:08:19 字数 1800 浏览 4 评论 0原文

我的目录结构如下: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝色星空 2024-11-13 10:08:19

尝试我最简单的配置,让我知道它是否有效:

import logging

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from gnukhata.lib.base import BaseController, render
from gnukhata import model
import gnukhata.model.meta as meta

init.py 中:

from unittest import TestCase

from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from pylons import url
from routes.util import URLGenerator
from webtest import TestApp
from pylons import config

import pylons.test

__all__ = ['environ', 'url', 'TestController']

# Invoke websetup with the current config file
SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])

environ = {}

class TestController(TestCase):

    def __init__(self, *args, **kwargs):
        wsgiapp = pylons.test.pylonsapp
        config = wsgiapp.config
        self.app = TestApp(wsgiapp)
        url._push_object(URLGenerator(config['routes.map'], environ))
        TestCase.__init__(self, *args, **kwargs)

Try my most simple configuration and let me know if it work:

import logging

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from gnukhata.lib.base import BaseController, render
from gnukhata import model
import gnukhata.model.meta as meta

In the init.py:

from unittest import TestCase

from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from pylons import url
from routes.util import URLGenerator
from webtest import TestApp
from pylons import config

import pylons.test

__all__ = ['environ', 'url', 'TestController']

# Invoke websetup with the current config file
SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])

environ = {}

class TestController(TestCase):

    def __init__(self, *args, **kwargs):
        wsgiapp = pylons.test.pylonsapp
        config = wsgiapp.config
        self.app = TestApp(wsgiapp)
        url._push_object(URLGenerator(config['routes.map'], environ))
        TestCase.__init__(self, *args, **kwargs)
中性美 2024-11-13 10:08:19

gnukhata/tests 目录中是否有 __init__.py ?如果不是,则 gnukhata.tests 不会被识别为模块,并且您无法从中导入。

如果这样的文件确实存在,您可以在此处发布 gnukhata/tests/__init__.py 中的导入语句(如果有)吗?

Is there an __init__.py in gnukhata/tests directory? If not, then gnukhata.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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文