I took me a little bit but, with the help of Mikko and Martin, I've got a couple of add-ons running tests with Travis CI.
Before setting up Travis CI, you have to make some changes to the Setup Script of your package.
In my case, my add-on package only works for Plone versions 4.1 and later, so I have added Products.CMFPlone as a dependency:
… install_requires=[ 'setuptools', 'Products.CMFPlone>=4.1', ], extras_require={ 'test': ['plone.app.testing'], }, …
Products.CMFPlone contains a cut down feature set: just the things I need to run my tests.
Setting up Travis CI is pretty easy: just sign in and activate your GitHub Service Hook
Now, you need to configure your Travis CI build with a .travis.yml file in the root of your repo:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: python | |
python: "2.7" | |
install: | |
- python bootstrap.py -c travis.cfg | |
- bin/buildout -c travis.cfg -q | |
script: bin/test |
Let's take a look at the travis.cfg buildout configuration file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[buildout] | |
extends = | |
http://svn.plone.org/svn/collective/buildout/plonetest/test-4.x.cfg | |
parts = test | |
package-name = your.package | |
package-extras = [test] | |
#test-eggs = Pillow | |
# network speedup | |
socket-timeout = 3 | |
allow-hosts = | |
*.plone.org | |
*.python.org | |
*.zope.org | |
docutils.sourceforge.net | |
effbot.org | |
prdownloads.sourceforge.net | |
[test] | |
eggs = | |
${buildout:package-name} ${buildout:package-extras} | |
${buildout:test-eggs} |
We also need to add a socket-timeout of 3 seconds (only available on zc.buildout >= 1.5.0) and a list of allow-hosts to download the dependencies. This is pretty important and will avoid timeouts as Travis CI has hard time limits and timeouts are between 10 and 15 minutes for test suite runs (1).
Last, we have to replace the eggs option on the test part; we need to do this because we don't want to include neither Plone or plone.app.upgrade on the tests.
Finally, you can add a Status Image with a link back to the result of your last build on your README.txt file:
.. image:: https://secure.travis-ci.org/collective/your.package.png :target: http://travis-ci.org/collective/your.package
To run the tests you only need to make a push to your GitHub repo. Easy, isn't it?
For a live example of all I mentioned above, take a look at the collective.prettydate package.
Travis CI is really easy to set up and fun to use; I strongly recommend it and, if you like it, please show your love donating.
No comments:
Post a Comment