Python-Django 使用 Hudson做CI服务器实践记
作者:Wally Yu
CSDN:http://blog.csdn.net/quicktest
微博:http://www.weibo.com/quicktest
我的环境:
开发环境: Windows XP
运行环境:Ubuntu 11
Python:2.7
Django:1.3.1
国内没有找到比较好的翻译和实践性的博文,于是去了Google,按照一篇文章的做法一步步实现,实践到“Displaying unit test results”的时候因为原文使用了自己的bash,而我需要使用Django自带的unit test的框架,于是修改这一段
原文:
What this isn’t doing it making some pretty graphs and charts. Let’s see about getting some of that enabled.
Pygments uses Nose tests for it’s unit tests. That’s pretty nice, because Nose includes a mechanism to output the format of the tests into Java-based JUnit format, and Hudson in turn knows how to make pretty pictures from that format. Since we installed the nose library earlier, we can take advantage of it. Probably the “right” way to do this would be to change the Makefile to invoke the tests that output XML for the unit tests. For right now, we’ll just shim it into place with new build steps.
python tests/run.py --with-xunit
Let’s get that graphed…
现在我的做法:
使用unittest-xml-reporting,官网:https://github.com/danielfm/unittest-xml-reporting#readme
具体做法:
1)shell输入安装unittest-xml-reporting:
pip install unittest-xml-reporting
2)在Django项目的Settings.py输入:
TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner' TEST_OUTPUT_VERBOSE = True TEST_OUTPUT_DESCRIPTIONS = True TEST_OUTPUT_DIR = 'unitTestResults'
python manage.py test
5)进入hudson的项目管理“configure”
http://Your IP Addr:8080/job/Your Project/configure
6)钩上“Publish Junit test result report”
7)地址填上“*/unitTestResults/*.xml”
8)保存
9)做个新Build,点 Build Now
10)Build完后会发现多出一个“Latest Test Results”的链接。点进去可以查看详细信息
11)同时会发现右边多出一个名为“Test Result Trend”的图
后面的就和原文一样了
Now you’ll see a new element in the web user interface called “Latest Test Result” which you can dig into. If you invoke “Build Now” again, it will start graphing the results of the tests and making that trend available in the project view. Right now this graph is going to be really darned boring, because there aren’t any changes between builds. Once more code starts rolling in, you’ll see changes with the number of tests being invoked. You can also click on that link and see the tests that were invoked. For python folks, remember that we’re shimming Python unit tests into a JUnit conceptual framework, so there are going to be some “leaky abstractions here”. In particular, test names, classes, and such may not alway match up with expectations. I have more details on how to enable XML output for a Django based test runner that I’ll post in another write up… uh, later.
按照原文的做法,我也顺利的生成了Code Coverage和Pylint
这里要感谢原作者Joe Heck
附上原文的链接:
http://www.rhonabwy.com/wp/2009/11/04/setting-up-a-python-ci-server-with-hudson/