【发布时间】:2014-03-25 13:44:34
【问题描述】:
我正在尝试使用 Django App 目录 (mysite/polls/tests.py) 中的 tests.py 文件进行简单的 Django 测试,但是每次运行“python manage.py test polls”时,我都会得到错误:
C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 3.0\helpers\pycharm\django_test_manage.py" test polls "C:\Users\<myname>\PycharmProjects\mysite"
Testing started at 8:40 PM ...
Creating test database for alias 'default'...
Type 'yes' if you would like to try deleting the test database 'test_<database>', or 'no' to cancel: Got an error creating the test database: permission denied to create database
根据我的阅读,显然 Heroku PG 使用共享数据库,所以我没有创建/销毁数据库的权限,这是测试所必需的。有没有明显的解决方案?我仍在本地驱动器上开发,因此任何解决方法都将不胜感激。我知道测试是编程的重要组成部分,所以我希望能够尽快实现测试方法。
我正在尝试使用TestCase django 类进行测试。
我正在使用什么:
1) Heroku Postgres 爱好开发计划
2) Postgres 9.3.3
3) Python 2.7.6
4) Django 1.6.1
编辑:
所以在做了更多的研究之后,我发现我可以在 settings.py 中覆盖我的DATABASES dict 变量以使用 SQLite 在本地进行测试(当 'test' 是 shell 中的参数时),但我仍然更喜欢 PostgreSQL实施,因为根据我的阅读,PostgreSQL 更加严格(我是它的粉丝)。
对于任何对我找到的半解决方案感兴趣的人(由 Stackoverflow 的另一位成员提供):
if 'test' in sys.argv:
DATABASES['default'] = {'ENGINE': 'django.db.backends.sqlite3'}
别忘了导入sys。
【问题讨论】:
标签: python django postgresql testing heroku