我正在尝试使用 nose 和 noseGAE 插件测试一些 GAE 模型。
教程展示了如何使用本教程中的 webapp 框架设置来运行测试 http://farmdev.com/projects/nosegae/ .但是由于我使用的是 django,所以我的 main.py 是:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
app = django.core.handlers.wsgi.WSGIHandler()
当我尝试跑 Nose 时:
$ nosetests --with-gae
我得到:
Traceback (most recent call last):
File "c:\Python27\Scripts\nosetests-script.py", line 8, in <module>
load_entry_point('nose==1.2.1', 'console_scripts', 'nosetests')()
File "C:\Python27\lib\site-packages\nose-1.2.1-py2.7.egg\nose\core.py", line 118, in __init__
**extra_args)
File "C:\Python27\lib\unittest\main.py", line 94, in __init__
self.parseArgs(argv)
File "C:\Python27\lib\site-packages\nose-1.2.1-py2.7.egg\nose\core.py", line 135, in parseArgs
self.config.configure(argv, doc=self.usage())
File "C:\Python27\lib\site-packages\nose-1.2.1-py2.7.egg\nose\config.py", line 338, in configure
self.plugins.configure(options, self)
File "C:\Python27\lib\site-packages\nose-1.2.1-py2.7.egg\nose\plugins\manager.py", line 284, in configure
cfg(options, config)
File "C:\Python27\lib\site-packages\nose-1.2.1-py2.7.egg\nose\plugins\manager.py", line 99, in __call__
return self.call(*arg, **kw)
File "C:\Python27\lib\site-packages\nose-1.2.1-py2.7.egg\nose\plugins\manager.py", line 167, in simple
result = meth(*arg, **kw)
File "build\bdist.win32\egg\nosegae.py", line 80, in configure
ImportError: No module named dev_appserver
我认为这是因为 django 依赖项,但接下来我尝试运行单个文件:
import unittest
from google.appengine.ext import testbed
class TestServicios(unittest.TestCase):
def setUP(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
def tearDown(self):
self.testbed.deactivate()
if __name__ == '__main__':
unittest.main()
然后:
$ python test_models.py
和:
Traceback (most recent call last):
File "test_models.py", line 2, in <module>
from google.appengine.ext import testbed
ImportError: No module named google.appengine.ext
GAE 信息 发布:1.7.3 运行时:python27
有人知道这是怎么回事吗?谢谢。
请您参考如下方法:
我推荐这个documentation .它显示了一个示例,您可以如何编写 testrunner.py 来加载您的测试类,这样您就可以拥有一个迷你测试框架。具体来说,以下代码就是您要查找的内容:
sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
sdk_path 是您的 google_appengine sdk 所在的位置。例如,在 Linux 上它可能是/usr/local/google_appengine。
