How to setup Jenkins for Python unit testing?
Jenkins is an open-source continuous integration tool. It is used to automate the tasks such as building, testing, and deployment of code. In this post, I will explain to 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 environments. Download Jenkins from Official Site and install the version corresponding 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.
get the default password from the file specified and paste it into 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 for the Python test case. ShiningPanda is one such plugin.
Once you complete the set up of Jenkins, from Dashboard, choose Manage Jenkins
from the left sidebar.
Navigate to Manage Jenkins > Manage Plugins > Available
.
In the search bar, type ‘ShiningPanda’ and install without restart.
Now from the Dashboard, navigate to Manage Jenkins > Global Tool Configuration > Python
.
Enter the name as ‘python’ and give the path of the python installation in the ‘Home or executable field’.
Now you need to install nose package on your local machine. nose extends unittest to make testing easier. Open the 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 a freestyle project.
In the next screen, under Build - choose Python builder.
In command filed type nosetests <path of your python code>
Once it is completed, click on build now. The build will start and once it is completed you can view the result for the console corresponding to each version.
If you want a sample python code for the unit test, please clone it from my Github repository.