简体   繁体   English

Google App引擎:Unity Works鼻子测试失败

[英]Google app engine: unitest works nosetest fails

I've wrote this simple code to test my model: 我已经编写了以下简单代码来测试我的模型:

class NDBTestCase(unittest.TestCase):
    def setUp(self):
        logging.getLogger().setLevel(logging.INFO)
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.owner = m_User(username="owner")
        self.owner.put()


    def tearDown(self):
        self.testbed.deactivate()


    def testClub(self):
        # this id is a manually assigned
        club = m_Club(id="1", name="test", email="test@test.com", description="desc", url="example.com",
                      owners=[self.owner.key], training_type=["balance", "stability"], tags=["test", "trento"])
        club.put()

in the models the owners is like this owners = ndb.KeyProperty(kind="User", repeated=True) 在模型中, owners就像这个owners = ndb.KeyProperty(kind="User", repeated=True)

if i run this code with unittest it works perfectly. 如果我使用unittest运行此代码,则效果很好。 I tried to run it with unitest and nosegae and it fails for a problem with the Key 我试图用unitestnosegae运行它, unitest由于Key问题而失败

Traceback (most recent call last):
  File "/Users/stefano/Documents/SW/gymcentral/tester_ndb.py", line 25, in setUp
    self.owner.put()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/model.py", line 3379, in _put
    return self._put_async(**ctx_options).get_result()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
    self.check_success()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/tasklets.py", line 368, in _help_tasklet_along
    value = gen.throw(exc.__class__, exc, tb)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/context.py", line 810, in put
    key = yield self._put_batcher.add(entity, options)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/tasklets.py", line 371, in _help_tasklet_along
    value = gen.send(val)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/context.py", line 350, in _put_tasklet
    ent._key = key
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/model.py", line 1363, in __set__
    self._set_value(entity, value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/model.py", line 1513, in _set_value
    value = _validate_key(value, entity=entity)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/model.py", line 1481, in _validate_key
    raise datastore_errors.BadValueError('Expected Key, got %r' % value)
BadValueError: Expected Key, got Key('User', 1)

any idea why? 知道为什么吗? i run the test from console with this command nosetests tester_ndb.py --with-gae 我使用以下命令从控制台运行测试:测试头nosetests tester_ndb.py --with-gae

I've gotten weird errors like this as well. 我也有类似这样的怪异错误。 I think there is a bug somewhere in Google's code. 我认为Google代码中的某个地方存在错误。 I got around it by tweaking my code to do the same thing in a slightly different way. 我通过调整代码以略有不同的方式执行相同的操作来解决了这个问题。

Try changing 尝试改变

self.owner.put()

to

ndb.put(self.owner)

Could you try running nose with the flag --without-sandbox ? 您可以尝试使用--without-sandbox标志运行吗?

There seems to be an older issue on the former tracker about the same thing. 在以前的跟踪器上,关于同一件事似乎存在一个较旧的问题。

https://code.google.com/p/nose-gae/issues/detail?id=60 https://code.google.com/p/nose-gae/issues/detail?id=60

I recently took over maintaining NoseGAE so I will look into the root cause as well but I am assuming it is something internal to the App Engine SDK. 我最近接手了维护NoseGAE的工作,因此我也将调查根本原因,但我认为这是App Engine SDK的内部问题。

EDIT: --without-sandbox was removed in NoseGAE 0.4.0 when I migrated it to dev_appserver2 编辑:--without-sandbox在我将其迁移到dev_appserver2时已在NoseGAE 0.4.0中删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Engine上传失败 - Google App Engine upload fails Python flask google-app-engine文件上传可在预览中工作,但在生产FileNotFoundError中失败:[Errno 2]没有这样的文件或目录: - Python flask google-app-engine file upload works in preview but fails in production FileNotFoundError: [Errno 2] No such file or directory: 将ReportLab与Google App Engine(Python)结合使用-在本地可运行,但在部署时会失败 - Using ReportLab with Google App Engine (Python) - works locally but fails when deployed Python的string.maketrans在家工作但在Google App Engine上失败 - Python's string.maketrans works at home but fails on Google App Engine 使用python的OSX Lion上的Google应用引擎失败 - Google app engine fails on OSX Lion with python 需要帮助将可在 Google App Engine、Flex 环境中运行的应用程序容器化 - Need help containerizing app that works in Google App Engine, Flex Environment 方法失败后如何在Google App Engine NDB中回滚 - How to rollback in Google App Engine NDB after method fails Google App Engine搜索API:可以硬编码,但不能与变量一起使用 - google app engine search API: works hardcoded but not with variable Google App Engine Cron作业失败并显示404错误 - Google App Engine cron job fails with 404 error 由于未通过就绪检查,Google App Engine 部署失败 - Google App Engine deployment fails because of failing readiness check
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM