开发者

Problem running pylon webtests. ImportError and TestController is not defined errror

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-开发者_如何学Cpackages/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


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)


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜