Set Up Travis CI For Django project

Reading Time : ~ .

Travis CI is a continuous integration service used to build and test applications hosted on GitHub. Travis CI supports integration with other tools such as coverage analyzers.

Why use Travis?

Travis CI runs your program's tests every time you commit to GitHub. you can easily discover your code breaks. setting up Travis-ci is very easy.

To run tests in Travis you have to create ".travis.yml" file in root directory.

.travis.yml file for Django application.

    language: python # => 1

    python: # => 2

      - "2.6"

      - "2.7"

    services: # => 3

      - mysql

    env: # => 4

      -DJANGO=1.8 DB=mysql
    install: # => 5

      - pip install -r requirements.txt

    before_script: # => 6

      - mysql -e 'create database test;' -u root
    script: # => 7

      - python manage.py test

Explanation for above comments:
1. By defining "language: python" application is developed in python language. 
2. Test your application in multiple versions of python by defining versions in python hook settings
3. Define services required for your application ex: elastic search, radis, etc in services.
4. Specify your Django version and database to use.
5. install application requirements.
6. before_script: as name defines this commands will run before running your actual test cases.
7. command to run tests.

Add above file to your Django project and commit it to GitHub. Now check the build status in Travis-CI.

    By Posted On
SENIOR DEVELOPER at MICROPYRAMID

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Django Unit Test cases with Forms and Views Swetha Naretla

By writing unit test cases, you can evaluate each code component in the initial stage itself and it'll improve your app/code performance. Which is the ...

Continue Reading...
How to Document API Requests using Django Rest Swagger Swetha Naretla

Django Rest Swagger is used to Document your API for eg., Listing all Your project Rest API's in the browser with brief description about the ...

Continue Reading...
Understanding django serializers with examples Vamsi Popuri

Serializers are used for “translating” Django models into other formats like xmi,json,yaml(YAML Ain’t a Markup Language)

from django.core import serializers
data = serializers.serialize("xml", SomeModel.objects.all())

Continue Reading...

Subscribe To our news letter

Subscribe to our news letter to receive latest blog posts into your inbox. Please fill your email address in the below form.
*We don't provide your email contact details to any third parties