30
Jan
5

Continuous Integration on Python

Hudson and Cruise Control are very popular among Java/.Net developers but when it comes to Python, ...
Hudson also seems to work on python!. Open source tools for Python continuous integration:

However, I just want a simple way to check out the code and run the tests. A Bash script and the Cron daemon is a good solution so far (last script update on Wed 25 Feb 2008):

 
cd /root/siga/src
export DJANGO_SETTINGS_MODULE="settings"
export PYTHONPATH=":/root/siga/src"
 
mailTo="developer1@sample.com, developer2@whatever.com"
 
analize_tests_output ()
{
   grep "FAIL:" $1 > failResults
   if [[ $? == 0 ]]
   then
      echo "There are tests failing!:" > tmp
      cat failResults >> tmp
      mail -s "Continuous integration report" $mailTo < tmp
   fi
   grep "ERROR:" $1 > errorResults
   if [[ $? == 0 ]]
   then
      echo "There are tests with errors!:" > tmp
      cat failResults >> tmp
      mail -s "Continuous integration report" $mailTo < tmp
      return
   fi
 
   rm -rf $1
}
 
are_there_changes()
{
        svn up > tmpsvnup
 
        grep "^U" tmpsvnup  2>  /dev/null > /dev/null
        if [[ $? == 0 ]]
        then
           return 1
        fi
 
        grep "^A" tmpsvnup  2>  /dev/null > /dev/null
        if [[ $? == 0 ]]
        then
           return 1
        fi
 
        grep "^D" tmpsvnup  2>  /dev/null > /dev/null
        if [[ $? == 0 ]]
        then
           return 1
        fi
 
        grep "^G" tmpsvnup  2> /dev/null > /dev/null
        if [[ $? == 0 ]]
        then
           return 1
        fi
 
        return 0
}
 
are_there_changes
changes=$?
if [[ $changes == 1 ]] # there are svn changes
then
   /etc/init.d/wservices stop
   sleep 2
   /etc/init.d/wservices start
 
   # running unittests tests and mocker tests
   python tests/runTests.py >> tmptest1 2>> tmptest1
   analize_tests_output tmptest1
   # runnin django tests
   python manage.py test core  2>> tmptest2 >> tmptest2
   analize_tests_output tmptest2
fi
 

The cron file:

 
# m h  dom mon dow   command
49 * * * * 	root	/root/siga/src/integrator.sh
 
Enjoyed reading this post?
Subscribe to the RSS feed and have all new posts delivered straight to you.
  • Dreur

    nice
    Thanks for the little script.

    Will use it for a php project.

  • http://carlosble.com Carlos Ble

    Hi Dreur, glad you find it useful. We’ve made some minor changes to the script:
    # running unittests tests and mocker tests
    python tests/runTests.py >> tmptest1 2>> tmptest1
    analize_tests_output tmptest1
    # runnin django tests
    python manage.py test core 2>> tmptest2 >> tmptest2
    analize_tests_output tmptest2

    Instead of using > we’re using >> to append because some errors were left out.
    Cheers :-)

  • http://carlosble.com Carlos Ble

    There is anocher change, “rm -rf $i” at the end of analize_tests_output.

  • http://www.belweder.velvet.beskidy.pl/ Hermiona

    hi, your site is discount. I do many thanks for get the job done

  • Kris

    Thanks for the script. I used your script as a starting point to make an automated build/test procedure for our software project. I was looking for something simpler than the continuous integration projects and this worked perfectly.

Celadon theme by the Themes Boutique
teeth bleaching
baldness treatment