To make running the tests as easy as possible, many software development teams implement a strategy called continuous integration. As its name implies, continuous integration integrates the test suite into the development process. Every time a change is made to the repository, the continuous integration system builds and checks that code.
How long will that process take? The typical story in a research lab is that, well, you don’t know whether it will work on your colleagues’ machine until you try rebuilding it on their machine. If you have a build system, it might take a few minutes to update the repository, rebuild the code, and run the tests. If you don’t have a build system, it could take all afternoon just to see if your new changes are compatible.
Scientists are good at creative insights, conceptual understanding, critical analysis, and consuming espresso. Computers are good at following instructions. Science would be more fun if the scientists could just give the computers the instructions and go grab an espresso.
Continuous integration servers allow just that. Based on your instructions, a continuous integration server can:
Since the first step the server conducts is to check out the code from a repository, we’ll need to put our code online to make use of this kind of server (unless we are able/willing to set up our own CI server).
Your work on the mean function has both code and tests. Let’s copy that code into its own repository and add continuous integration to that repository.
Travis is a continous integration server hosting platform. It’s commonly used in Ruby development circles as well as in the scientific Python community.
To use Travis, all you need is an account. It’s free so someone in your group should sign up for a Travis account. Then follow the instructions on the Travis website to connect your Travis account with GitHub.
A file called .travis.yml
in your repository will signal to Travis that you want to build and test this repository on Travis-CI. Such a file, for our purposes, is very simple:
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "nightly"
# command to install dependencies
install:
- "pip install -r requirements.txt"
# command to run tests
script: py.test
However, the exact syntax is very important, https://lint.travis-ci.org/ can be used to check for typographic errors. You can see how the Python package manager, pip
, will use your requirements.txt
file from the previous exercise. That requirements.txt
file is a conventional way to list all of the python packages that we need. If we needed pytest, numpy, and pymol, the requirements.txt
file would look like this:
numpy
pymol
pytest
We gave the example of Travis because it’s very very simple to spin up. While it is able to run many flavors of Linux, it currently doesn’t support other platforms as well. Depending on your needs, you may consider other services such as: