【发布时间】:2014-09-26 08:23:33
【问题描述】:
我似乎无法弄清楚如何集成我当前的 Django 项目以在 Travis CI 上运行测试。现在,我已将 PostgreSQL 设置为在运行单元测试时在本地计算机上运行。
language: python
python:
- 3.4.1
addons:
postgresql: "9.3"
before_script:
- psql -U postgres -c "create extension postgis"
- psql -c 'create database travis_ci_test;' -U postgres
install:
- pip install -r requirements.txt
- pip install coveralls
script:
coverage run --source=calculator manage.py test
after_success:
coveralls
特拉维斯告诉我:
$ coverage run --source=calculator manage.py test
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database
Type 'yes' if you would like to try deleting the test database 'test_dk5va592r6j0v', or 'no' to cancel:
现在我有一个 hacky 设置来处理本地数据库和我的 heroku 数据库之间的切换:
import dj_database_url
if DEBUG:
DATABASE_URL = 'postgres://localhost/storage'
else:
DATABASE_URL = 'postgres://somerealurl'
DATABASES = {'default': dj_database_url.config(default=DATABASE_URL)}
有人有解决我问题的好方法吗?看来我需要能够在 Travis 上创建一个 PostgreSQL,然后运行我的测试,这样我才能得到覆盖。每当签入代码时,Debug 也必须设置为 False。
如果您能发布一个可以工作的 Travis、DJango 和 PSQL 设置,那就太棒了!
【问题讨论】:
标签: python django postgresql heroku travis-ci