How to setup Jenkins for Python unit testing?

How to setup Jenkins for Python unit testing?

Jenkins is an open source continous integration tool. It is used to automate the tasks such as building, testing and deployment of code. In this post, I will explain you how to configure Jenkins to do unit testing with Python.

Download and Install Jenkins

Jenkins is cross platform and can be used on windows, Linux, Mac OS and Solaris enviornments. Download Jenkins from Official Site and install the version corresponing to your operating system. Once the installation is completed, the jenkins will run automatically on http://localhost:8080/, the page will open in your default browser.

alt text

get the default password from the file specified and paste it in the password field.

[Tip]: You can copy paste the entire URL in the browser itself to get the password

In the next screen, select ‘Install suggested plugins’.

Once the suggested plugins are installed we need to install a plugin which for Python test case. ShiningPanda is one such plugin.

Once you complete the set up of Jenkins, from Dashboard, choose Manage Jenkins from left side bar.

Navigate to Manage Jenkins > Manage Plugins > Available .

In the search bar, type ‘ShiningPanda’ and install without restart .

alt text

Now from the Dashboard, navigate to Manage Jenkins > Global Tool Configuartion > Python.

Enter the name as ‘python’ and give the path of the python installation in the ‘Home or executable field’.

alt text

Now you need to install nose package on your local machine. nose extends unittest to make testing easier. Open command prompt and type in the following.

pip install nose

Set up new project in Jenkins

Go back to Jenkins Dashboard and select ‘New Item’. Enter your project name and choose freestyle project.

alt text

In the next screen, under Build - choose Python builder.

In command filed type nosetests <path of your python code>

alt text

Once it is completed, click on build now. The build will start and once it is completed you can view the result for console correposning to each version.

alt text

If you want a sample python code for unit test, please clone it from my Github repository.

comments powered by Disqus