Tox on Jenkins with ShiningPanda plugin

Tox is an amazing tool to package, test and deploy your Python project. This tutorial does not aim at describing how to setup your project with tox as its documentation is quite good. We'd rather have a look on how to setup a tox enabled project on Jenkins with ShiningPanda plugin.

Sample project

This tutorial uses a sample project to describe all the steps of the process. The sources of this project can be found here.

This sample project is organized like this:

/media/blog/15/tree.png

Note the tox.ini file next to the setup.py which contains the configuration for tox. Here is its content:

 1 [testenv]
 2 deps=nose
 3 commands=
 4     nosetests --with-xunit --xunit-file=junit-{envname}.xml tests
 5 
 6 [testenv:docs]
 7 basepython=python
 8 changedir=doc # or whereever you keep your sphinx-docs
 9 deps=sphinx
10     pytest
11 commands=
12     py.test --tb=line -v --junitxml=junit-{envname}.xml check_sphinx.py

What does it do?

  • On default test environments, it runs tests located in tests folder with nose and produces XML reports.
  • On docs test environment, it executes check_sphinx.py with py.test to check the generation of the sphinx documentation (this example and check_sphinx.py script come from tox's documentation).

Our goal is to setup this project on Jenkins with ShiningPanda plugin for Python 2.7, Python 3.2 and PyPy, with an additional documentation check.

Global configuration

Unlike other builders, tox is able to find Python installations by itself, as long as they are in standard locations. However if you have a Python installation in a non standard location, declaring it in Jenkins will add it to the PATH, so that tox will be able to find it.

To do so, click on Manage Jenkins > Configure System, step in the Python section, Add Python then give the installation a name and enter its home folder (ie. its PYTHOHOME):

/media/blog/15/installation.png

Create a new job

/media/blog/15/new.png

First of all, create a new job, enter its name (here toxsample) and select Build multi-configuration project before validating.

Basic setup

/media/blog/15/source.png

As usual, setup:

  • The name and description.
  • The source repository, here https://github.com/shiningpanda/sample.git.
  • The build trigger policy: checking for modifications every five minutes in this example.

Tox setup

Here is the core of the solution:

/media/blog/15/axis.png

First of all, add a Tox axis.

/media/blog/15/tox_builder.png

Then select the environments you want to test on:

  • The default test environments are directly available by checking the corresponding box, ie. py27 for Python 2.7, py32 for Python 3.2 and pypy for PyPy.
  • To execute some custom test environments, enter their names separated by space in the dedicated text field: docs in our sample project.
/media/blog/15/add_builder.png

A Tox Builder is also required.

/media/blog/15/builder.png

Finish by entering the path to the tox.ini file and checking the Recreate box if you want to force recreation of virtual environments on each build.

Post-build actions

/media/blog/15/postbuild.png

Add all the desired post-build actions. Here Jenkins is asked to parse the XML test reports and to send mails on failure.

Results

/media/blog/15/result.png

Finally start a new build: execution results by test environments are directly available on the main page of the project.

Comments

No comments yet.

Post your comment