gpt4 book ai didi

python - 谷歌应用引擎: unitest works nosetest fails

转载 作者:行者123 更新时间:2023-12-01 05:00:02 26 4
gpt4 key购买 nike

我编写了这个简单的代码来测试我的模型:

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()

在模型中,owners 是这样的 owners = ndb.KeyProperty(kind="User",repeated=True)

如果我使用单元测试运行此代码,它会完美运行。我尝试使用 unitestnosegae 运行它由于 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)

知道为什么吗?我使用此命令从控制台运行测试 nosetests tester_ndb.py --with-gae

最佳答案

你能尝试用--without-sandbox标志运行nose吗?

以前的跟踪器上似乎有一个关于同一件事的较旧问题。

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

我最近接管了 NoseGAE 的维护工作,因此我也会调查根本原因,但我假设这是 App Engine SDK 内部的问题。

编辑:当我将它迁移到 dev_appserver2 时,NoseGAE 0.4.0 中删除了 --without-sandbox

关于python - 谷歌应用引擎: unitest works nosetest fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26468187/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com