Using Travis-CI With Python and Django
I’ve been using Travis-CI for a while now. Both my personal projects, and even several of the libraries we maintain at DISQUS rely on it for Continuous Integration. I figured it was about time to confess my undenying love for Travis, and throw up some notes about the defaults we use in our projects.
Getting started with Travis-CI is pretty easy. It involves putting a
.travis.yml file in the root of
your project, and configuring the hooks between GitHub and Travis. While it’s not always easy to get the hooks configured
when you’re using organizations, I’m not going to talk much about that. What I do want to share is how we’ve structured
our configuration files for our Django and Python projects.
.travis.yml might look something like this:
1 2 3 4 5 6 7 8
Most of the projects themselves use Django, which also means they need to test several Django versions. Travis makes this very simple with its matrix builds. In our case, we need to setup a DJANGO matrix, and ensure it gets installed:
1 2 3 4 5 6 7
Additionally we generally conform to pep8, and we always want to run pyflakes against our build. We also use a custom
version of pyflakes which allows us to filter out warnings, as those are never critical errors. Add this in is pretty
simple using the
before_script hook, which gets run before the tests are run in
1 2 3 4 5 6 7 8
When all is said and done, we end up with something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Travis will automatically matrix each environment variable with each Python version, so you’ll get a test run for every combination of the two. Pretty easy, right?