我正在尝试使用他们在Python的本地单元测试页面上放置的确切代码来学习使用Google App Engine进行单元测试(https://cloud.google.com/appengine/docs/python/tools/localunittesting).但我无法弄清楚这个错误:
ImportError: Start directory is not importable: 'testmem.py'
Run Code Online (Sandbox Code Playgroud)
我只是将他们的简单测试框架用作testrunner.py,并在名为testmem.py的文件中使用他们的数据存储和Memcache测试.我从项目根目录调用测试为:
<me>$ python testrunner.py ~/google_appengine testmem.py
Run Code Online (Sandbox Code Playgroud)
这符合我的用法:%prog SDK_PATH TEST_PATH.
我的文件结构是:
__init__.py
app.yaml
testrunner.py
testmem.py
helloworld.py
Run Code Online (Sandbox Code Playgroud)
谁能告诉我这里我做错了什么?提前致谢.
完整的错误消息:
Traceback (most recent call last):
File "testrunner.py", line 30, in <module>
main(SDK_PATH, TEST_PATH)
File "testrunner.py", line 17, in main
suite = unittest.loader.TestLoader().discover(test_path)
File "/usr/lib/python2.7/unittest/loader.py", line 204, in discover
raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: 'testmem.py'
Run Code Online (Sandbox Code Playgroud)
testrunner.py:
#!/usr/bin/python
import optparse
import sys
import …
Run Code Online (Sandbox Code Playgroud) 我在ScoredDocument中获取特定文档字段时遇到问题.这必须非常简单,但文档似乎并未涵盖它.
我已在索引中正确创建索引,文档并搜索带有结果的文档.文档只有一个title属性和一个note属性.如何获得标题或说明?这是服务器代码:
class SearchHandler(webapp2.RequestHandler):
def get(self):
index = search.Index(name="myIndex")
query_string = "dog"
try:
results = index.search(query_string)
logging.info(results)
self.response.out.write("""<html><body>
Here are the results from the search for "dog":""")
# Iterate over the documents in the results
for note in results:
self.response.out.write(note.fields)
self.response.out.write(note.fields.title) # HERE IS PROBLEM
self.response.out.write("</body></html>")
except search.Error:
logging.exception('Search failed')
Run Code Online (Sandbox Code Playgroud)
没有尝试获取标题的输出是正确的,我得到一个ScoredDocument字段:
[search.TextField(name=u'title', value=u'A note with a dog'), search.TextField(name=u'note', value=u'hamster'), search.DateField(name=u'updated', value=datetime.datetime(2014, 4, 10, 0, 0)), search.DateField(name=u'created', value=datetime.datetime(2014, 4, 10, 0, 0))]
Run Code Online (Sandbox Code Playgroud)
尝试以这种方式获得标题的错误是:在get self.response.out.write(note.fields.title)中AttributeError:'list'对象没有属性'title'
有人能帮忙吗?谢谢