小编Mik*_*ike的帖子

App Engine单元测试:ImportError:开始目录不可导入

我正在尝试使用他们在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)

python google-app-engine unit-testing

7
推荐指数
1
解决办法
9774
查看次数

pgAdmin4 导入文件错误 - 找不到文件

我在 Mac 上将 csv 文件导入到 pgAdmin4 时遇到问题 - 它根本找不到该文件。这太简单了,我希望只是有一个我未能设置的设置。

在表的导入/导出数据功能中,有一个导入/导出对话框,如下所示: 在此输入图像描述

但是,它找不到该文件: 在此输入图像描述

当你给它提供错误的文件路径时,该错误看起来就像标准的 python 错误。但它是正确的 - 这就是文件所在的位置:“/tmp/person616.csv” - 我什至没有输入名称/路径,我浏览到了它。

其他人也发生过这种情况吗?知道如何解决吗?

csv postgresql pgadmin pgadmin-4 postgresql-9.6

5
推荐指数
2
解决办法
1万
查看次数

如何从GAE Search API中的ScoredDocument返回一个字段 - Python

我在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'

有人能帮忙吗?谢谢

python google-app-engine google-search-api

2
推荐指数
1
解决办法
632
查看次数