How to run a control command in a test file on Travis?

In one of my test files, I call the Django control command:

def setUpModule():
    management.call_command('loaddata', 'frontend/fixtures/chemicals.json',
                            verbosity=0)
    management.call_command('create_indexes_and_matviews',
                            db_name, db_user, db_pass,
                            verbosity=2)

This test works fine when I run it locally using manage.py test.

However, on Travis I get this error:

======================================================================
ERROR: setUpModule (frontend.tests.test_api_views)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/.../frontend/tests/test_api_views.py", line 35, in setUpModule
    verbosity=2)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 95, in call_command
    raise CommandError("Unknown command: %r" % name)
CommandError: Unknown command: 'create_indexes_and_matviews'

How can I tell Travis about the team?

This is my Travis file:

language: python
python:
  - "2.7"
addons:
  postgresql: "9.3"
env:
  - SECRET_KEY=test DB_NAME=dbtest DB_USER=test DB_PASS=test
before_install:
  - export DJANGO_SETTINGS_MODULE=....settings.local
  - export PYTHONPATH=$HOME/builds/...
install:
 - pip install -r requirements.txt
 - pip install -r requirements/local.txt
before_script:
 - psql -U postgres -c 'CREATE DATABASE dbtest;'
 - psql -U postgres -c "CREATE EXTENSION postgis" -d dbtest
 - psql -U postgres -c "CREATE EXTENSION postgis_topology" -d dbtest
 - psql -U postgres -c "CREATE USER test WITH CREATEUSER PASSWORD 'test';"
 - psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE dbtest to test;"
 - psql -U postgres -c "ALTER USER test CREATEDB;"
 - cd frontend && python manage.py migrate
script:
 - python manage.py test

Is there anything I need to add so that he knows where to look for control commands?

+4
source share
1 answer

From my practice, I know two reasons for this problem.

A. No the_appwith create_indexes_and_matviewsspecified in settings.INSTALLED_APPS(it could be skipped, excluded in if / else or try / except magic)

To check the actual settings, try adding the following command to the Travis file

echo "from django.conf import settings;print(settings.INSTALLED_APPS)" |  python manage.py shell

B. . travis :

echo "from the_app.management.commands.create_indexes_and_matviews import Command" |  python manage.py shell

, .

0

All Articles