Get Travis-CI to do your Python packaging tests for you

I’ve been writing some API wrapper libraries recently – dead simple stuff in Ruby and Python that make calling my company’s OAuth-protected API a bit easier.

With the code on GitHub, and some basic unit tests in place, I wanted to test out Travis CI for continuous integration. Getting things setup on Travis is dead simple, but what I really wanted to do was test the packaged-and-installed library rather than testing it straight from source.

To do this there are a few script lines in the .travis.yml file:

install:
 - python setup.py sdist --formats=zip -k
 - find ./dist -iname "*.zip" -print0 | xargs -0 pip install
script:
 - python PACKAGENAME_GOES_HERE/test/__init__.py
  1. The first packages the library as a .ZIP file as would be uploaded to PyPI
  2. The second looks for all .ZIP files in the build (which here will just be the package we created from the first line) and pipes the filenames through to pip install installing the packages as would an end-user
  3. The third runs a small unit and system test suite

This way, every time we check code in to GitHub we can ensure that it:

  • The packaging configuration is correct and generates a sensible package
  • The packaging configuration has all the prerequisites listed correctly and can be pulled down from PyPI
  • The packaged and installed library works

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.