开发者

Can't import django packages with nosegae

开发者 https://www.devze.com 2023-04-05 19:01 出处:网络
I am trying to get started with using nosegae, however I run into the issue that I can\'开发者_JS百科t seem to get it to pass even the simplest of cases when using django.

I am trying to get started with using nosegae, however I run into the issue that I can'开发者_JS百科t seem to get it to pass even the simplest of cases when using django.

when running without the --without-sandbox flag both the following tests fail

def test_import_django  ():
    import django

def test_import_django_http  ():
    import django.http

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 1
97, in runTest
    self.test(*self.arg)
  File "C:\Users\User\Desktop\TDD_GAE\myproj\tests.py", line 2, in test_import_d
jango
    import django
  File "C:\Python27\lib\site-packages\nosegae-0.1.9-py2.7.egg\nosegae.py", line
207, in find_module
    return super(HookMixin, self).find_module(fullname, path)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\de
v_appserver.py", line 1505, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\de
v_appserver.py", line 1998, in find_module
    search_path)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\de
v_appserver.py", line 1505, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\de
v_appserver.py", line 2119, in FindModuleRestricted
    result = self.FindPathHook(submodule, submodule_fullname, path_entry)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\de
v_appserver.py", line 2219, in FindPathHook
    return self._imp.find_module(submodule, [path_entry])

Howevere if I do use --without-sandbox at least the first test passes

myproj.tests.test_import_django ... ok
myproj.tests.test_import_django_http ... ERROR

======================================================================
ERROR: myproj.tests.test_import_django_http
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 1
97, in runTest
    self.test(*self.arg)
  File "C:\Users\User\Desktop\TDD_GAE\myproj\tests.py", line 5, in test_import_d
jango_http
    import django.http
  File "C:\Program Files (x86)\Google\google_appengine\lib\django_1_2\django\htt
p\__init__.py", line 9, in <module>
    from mod_python.util import parse_qsl
  File "C:\Python27\lib\site-packages\nosegae-0.1.9-py2.7.egg\nosegae.py", line
199, in find_module
    mod_path = self.find_mod_path(fullname)
  File "C:\Python27\lib\site-packages\nosegae-0.1.9-py2.7.egg\nosegae.py", line
251, in find_mod_path
    _sf, path, _desc= self._imp.find_module(top, None)
AttributeError: 'str' object has no attribute 'find_module'

Has anyone encountered and know how I can go about past this?

Edit

It seems that the issue is recursive imports

def test_import_pdb ():
    import pdb
    pdb.set_trace ()

part of the stack trace is

File "C:\Python27\lib\pdb.py", line 72, in __init__
  import readline

notice that an import in __init__ of django.http is also part of the stack trace


Read https://docs.djangoproject.com/en/dev/topics/testing/ about Django testing.

As I know it's better to use unittest or doctest shipped with django as it have several improvements for django-specific testing like form field output testing and some database features. Hovewer it's not essential and if you want to continue using nose - think you missed django environment setup:

from django.test.utils import setup_test_environment
setup_test_environment()

This lines needed to run your tests outside of ./manage.py --test

UPD Yeah my previous thought's were wrong. So I just digged into sources of nose and nose-gae, and what I think - check HardenedModulesHook definition in your nose version, cause in trunk of nose I've found following:

class HardenedModulesHook(object):
    ...
    def __init__(self,
               module_dict,
               imp_module=imp,
               os_module=os,
               dummy_thread_module=dummy_thread,
               pickle_module=pickle):
    ...

That gives following - when noseGAE plugin begin() method is executed -> there self._install_hook(dev_appserver.HardenedModulesHook) is called which declares mixed-hook class and creates it's instance like self.hook = Hook(sys.modules, self._path). <- There is HardenedModulesHook.__init__ called with second argument as mystic '_path' however in NOSE this argument should be 'imp' module by default -> That makes an exception you've got:

    _sf, path, _desc= self._imp.find_module(top, None)
AttributeError: 'str' object has no attribute 'find_module'  

So I think it might be a problem with nose-gae :(

0

精彩评论

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

关注公众号