在 Google App Engine 上使用 App Engine 补丁时设置单元测试时出现问题
我在为应用程序引擎补丁解决方案编写单元测试时遇到很多麻烦。
我在专家交流(http://www.experts-exchange.com/Programming/Languages/Scripting/Python/Q_26509115.html)上问过这个问题,但已经有两周了没有答案 - 希望 SO 工作人员可以改进一下!
我已经尝试了在互联网上找到的所有内容,我当前的设置是使用nose-aep,但我也尝试了标准单元测试框架,但它给出了几乎相同的问题(问题似乎是应用程序引擎补丁,但尚不清楚如何修复它)。
使用最简单的测试:
def test():
#pass
assert False
通过和失败都按预期运行,但显示了一个不影响结果的异常:
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'print_exc'" in <bound method Signal._remove_receiver of <django.dispatch.dispatcher.Signal object at 0x22da290>> ignored
一旦导入模型或引用模型的任何其他文件,例如
from application.models import *
我收到错误这表明应用程序引擎补丁设置不正确。我在下面包含了日志输出。
任何帮助表示赞赏!
当使用nose-aep时,错误是:
/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 /Applications/PyCharm-96.1063.app/helpers/pydev/pydevd.py --client 127.0.0.1 --port 61552 --file /usr/local/bin/nosetests-script.py --with-gae --without-sandbox -w tests/
Connected to pydevd (version 1.1)
pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
nose.config: INFO: Set working dir to /Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/tests
Running on app-engine-patch 1.1
Failure: AttributeError ('module' object has no attribute 'User') ... ERROR
======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'User')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/nose-0.11.4-py2.5.egg/nose/loader.py", line 382, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Python/2.5/site-packages/nose-0.11.4-py2.5.egg/nose/importer.py", line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Python/2.5/site-packages/nose-0.11.4-py2.5.egg/nose/importer.py", line 86, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/tests/tests.py", line 5, in <module>
from application.models import *
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/application/models.py", line 4, in <module>
from ragendja.auth.hybrid_models import User
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/common/appenginepatch/ragendja/auth/hybrid_models.py", line 3, in <module>
from ragendja.auth.google_models import GoogleUserTraits
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/common/appenginepatch/ragendja/auth/google_models.py", line 5, in <module>
from ragendja.auth.models import EmailUserTraits
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/common/appenginepatch/ragendja/auth/models.py", line 1, in <module>
from django.contrib.auth.models import *
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist/py_zipimport.py", line 213, in load_module
exec code in mod.__dict__
File "/Users/craigedmunds/Documents/source/reciply/webapplication/trunk/common/zip-packages/django-1.1.zip/django/contrib/auth/models.py", line 457, in <module>
User = cache.app_models['auth']['user'] = module.User
AttributeError: 'module' object has no attribute 'User'
-------------------- >> begin captured logging << --------------------
root: WARNING: Can't open zipfile /Users/craigedmunds/Documents/source/reciply/webapplication/trunk/common/zip-packages/.DS_Store: BadZipfile: File is not a zip file
root: INFO: zipimporter('/Users/craigedmunds/Documents/source/reciply/webapplication/trunk/common/zip-packages/django-1.1.zip', '')
root: WARNING: Could not read datastore data from /var/folders/yb/yb1f3LPqE50UqVxSbqvYN++++TI/-Tmp-/django_reciply.datastore
root: WARNING: Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
root: WARNING: Could not read datastore data from /var/folders/yb/yb1f3LPqE50UqVxSbqvYN++++TI/-Tmp-/nosegae.datastore
root: WARNING: Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 1 test in 0.102s
FAILED (errors=1)
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'print_exc'" in <bound method Signal._remove_receiver of <django.dispatch.dispatcher.Signal object at 0x23da290>> ignored
当使用标准python单元测试框架时:
/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 /Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py /Users/craigedmunds/Documents/source/reciply/webapplication/trunk/tests//
Testing started at 9:22 PM ...
Traceback (most recent call last):
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 58, in <module>
modules = loadModulesFromFolderRec(a[0])
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 42, in loadModulesFromFolderRec
os.path.walk(folder, walkModules, modules)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py", line 290, in walk
func(arg, top, names)
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 38, in walkModules
modules.append(loadSource(os.path.join(dirname, name)))
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 31, in loadSource
module = imp.load_source(moduleName, fileName)
File "/Users/craigedmunds/Documents/source/reciply/webapplication/trunk/tests//tests.py", line 6, in <module>
from application.models import *
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/application/models.py", line 4, in <module>
from ragendja.auth.hybrid_models import User
ImportError: No module named ragendja.auth.hybrid_models
Process finished with exit code 1
Empty test suite.
I'm having a lot of trouble writing unit tests for my app engine patch solution.
I've asked this question on experts exchange (http://www.experts-exchange.com/Programming/Languages/Scripting/Python/Q_26509115.html) but it's been there for two weeks with no answer - hopefully the SO crew can improve on that!!
I've tried everything I've found on the internet, my current setup is using nose-aep, but I have also tried the standard unit test framework but it gives pretty much the same problem (the issue seems to be app engine patch, but it's not clear how to fix it).
Using the simplest test:
def test():
#pass
assert False
Both the pass and fail run as expected but I'm getting an exception shown which isn't affecting the outcome:
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'print_exc'" in <bound method Signal._remove_receiver of <django.dispatch.dispatcher.Signal object at 0x22da290>> ignored
As soon as I import the models, or any other file which references the models e.g.
from application.models import *
I get an error which suggests app engine patch isn't setting up correctly. I've included the log output below.
Any help appreciated!!
When using nose-aep the error is :
/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 /Applications/PyCharm-96.1063.app/helpers/pydev/pydevd.py --client 127.0.0.1 --port 61552 --file /usr/local/bin/nosetests-script.py --with-gae --without-sandbox -w tests/
Connected to pydevd (version 1.1)
pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
nose.config: INFO: Set working dir to /Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/tests
Running on app-engine-patch 1.1
Failure: AttributeError ('module' object has no attribute 'User') ... ERROR
======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'User')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/nose-0.11.4-py2.5.egg/nose/loader.py", line 382, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Python/2.5/site-packages/nose-0.11.4-py2.5.egg/nose/importer.py", line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Python/2.5/site-packages/nose-0.11.4-py2.5.egg/nose/importer.py", line 86, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/tests/tests.py", line 5, in <module>
from application.models import *
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/application/models.py", line 4, in <module>
from ragendja.auth.hybrid_models import User
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/common/appenginepatch/ragendja/auth/hybrid_models.py", line 3, in <module>
from ragendja.auth.google_models import GoogleUserTraits
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/common/appenginepatch/ragendja/auth/google_models.py", line 5, in <module>
from ragendja.auth.models import EmailUserTraits
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/common/appenginepatch/ragendja/auth/models.py", line 1, in <module>
from django.contrib.auth.models import *
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist/py_zipimport.py", line 213, in load_module
exec code in mod.__dict__
File "/Users/craigedmunds/Documents/source/reciply/webapplication/trunk/common/zip-packages/django-1.1.zip/django/contrib/auth/models.py", line 457, in <module>
User = cache.app_models['auth']['user'] = module.User
AttributeError: 'module' object has no attribute 'User'
-------------------- >> begin captured logging << --------------------
root: WARNING: Can't open zipfile /Users/craigedmunds/Documents/source/reciply/webapplication/trunk/common/zip-packages/.DS_Store: BadZipfile: File is not a zip file
root: INFO: zipimporter('/Users/craigedmunds/Documents/source/reciply/webapplication/trunk/common/zip-packages/django-1.1.zip', '')
root: WARNING: Could not read datastore data from /var/folders/yb/yb1f3LPqE50UqVxSbqvYN++++TI/-Tmp-/django_reciply.datastore
root: WARNING: Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
root: WARNING: Could not read datastore data from /var/folders/yb/yb1f3LPqE50UqVxSbqvYN++++TI/-Tmp-/nosegae.datastore
root: WARNING: Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 1 test in 0.102s
FAILED (errors=1)
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'print_exc'" in <bound method Signal._remove_receiver of <django.dispatch.dispatcher.Signal object at 0x23da290>> ignored
When using the standard python unit test framework:
/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 /Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py /Users/craigedmunds/Documents/source/reciply/webapplication/trunk/tests//
Testing started at 9:22 PM ...
Traceback (most recent call last):
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 58, in <module>
modules = loadModulesFromFolderRec(a[0])
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 42, in loadModulesFromFolderRec
os.path.walk(folder, walkModules, modules)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py", line 290, in walk
func(arg, top, names)
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 38, in walkModules
modules.append(loadSource(os.path.join(dirname, name)))
File "/Applications/PyCharm-97.8.app/helpers/pycharm/utrunner.py", line 31, in loadSource
module = imp.load_source(moduleName, fileName)
File "/Users/craigedmunds/Documents/source/reciply/webapplication/trunk/tests//tests.py", line 6, in <module>
from application.models import *
File "/Users/craigedmunds/Documents/Source/reciply/webapplication/trunk/application/models.py", line 4, in <module>
from ragendja.auth.hybrid_models import User
ImportError: No module named ragendja.auth.hybrid_models
Process finished with exit code 1
Empty test suite.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用过
nose-aep
。我们将nosetests
与 google-app-engine 插件结合使用。设置非常简单,基本上只需按照底部提供的链接即可。抱歉,我无法使用nose-aep
帮助解决您的具体问题。祝你好运。完整概述,包括如何安装:
http://www.cuberick.com /2008/11/unit-test-your-google-app-engine-models.html
使用示例:
http://farmdev.com/projects/nosegae/
用于鼻子测试的 GAE 插件:
http://code.google.com/p/nose-gae/
Nosetest 插件网站,带有文档:
http://somethingaboutorange.com/mrl/projects/nose/1.0.0/
I haven't used
nose-aep
. We usenosetests
with the google-app-engine plugin. It was very easy to set up, basically by following the links provided at the bottom. Sorry I can't help with your specific question usingnose-aep
. Good luck.Complete overview, including how to install:
http://www.cuberick.com/2008/11/unit-test-your-google-app-engine-models.html
Examples of use:
http://farmdev.com/projects/nosegae/
The GAE plugin for nose tests:
http://code.google.com/p/nose-gae/
Nosetest's plugin site, with documentation:
http://somethingaboutorange.com/mrl/projects/nose/1.0.0/