Quality code is...
coverage.py
, figleaf
)Pylint
, pyflakes
, pychecker
)hotshot
, cProfile
)Selenium
, Windmill
)PyMetrics
, pygenie
)sloccount
)It looks like quality, it sounds like quality, but it's not quite quality.
http://cpants.perl.org/kwalitee.html
manage.py test
is baked in
...but Django's test suite has fails under certain conditions as do many third-party apps. We just want to run tests on our code.
manage.py test myapp1 myapp2 myapp3
doesn't scaledjango-nose
: manage.py test myproject
A simple example with coverage.py
1 $ coverage -x manage.py test
2 $ coverage report --show-missing
Sample output:
Name Stmts Miss Cover Missing
----------------------------------------------------------------
django/views/__init__ 0 0 100%
django/views/decorators/__init__ 0 0 100%
django/views/decorators/cache 32 19 40% 16-17, 39-50, 54-60
django/views/decorators/csrf 22 12 45% 6-7, 22-26, 35-38, 48
django/views/defaults 11 5 54% 13-14, 24, 34-35
-----------------------------------------------------------------
TOTAL 65 36 44%
A simple example (what happens when y=0
?)
1 def divide(x, y):
2 """
3 Divides the first argument by the second argument
4
5 >>> divide(8, 2)
6 4
7 """
8 z = x/y
9 return z
Static analysis of your project looking for "suspicious" code such as:
We use Pylint for a few reasons:
Can you make a build in one step?
The Joel Test
Pick one and use it for all your projects
1 #!/bin/bash
2
3 cd $WORKSPACE
4 TEST_SETTINGS_MODULE=$PROJECT_NAME.conf.test.settings
5 COVER_PACKAGE=$PROJECT_NAME.apps
6
7 echo "## Setting up virtualenv"
8 virtualenv -q ve
9 source ./ve/bin/activate
10
11 echo "## Installing project and dependencies"
12 python setup.py --quiet develop
13 yes w | pip install -q -r dependencies/production.pip
14
15 echo "## Installing testing tools"
16 pip install -q -e git+git://github.com/jbalogh/django-nose.git#egg=django-nose
17 pip install -q -e git+git://github.com/cmheisel/nose-xcover.git#egg=nosexcover
18 pip install -q coverage
19 pip install -q pylint
20
21 echo "## Running tests with coverage"
22 manage.py test -v0 --noinput --settings=$TEST_SETTINGS_MODULE \
23 --with-xunit \
24 --with-coverage --cover-package=$COVER_PACKAGE --with-xcoverage
25
26 echo "## Running Pylint"
27 pylint --rcfile=$WORKSPACE/.pylintrc -f parseable $PROJECT_NAME > pylint.txt
28 PYLINT_SCORE=`grep "Your code has been rated" pylint.txt | \
29 cut -d" " -f7|cut -d"/" -f1`
30 echo "YVALUE=$PYLINT_SCORE" > pylint.properties
Just use Hudson
Titus Brown, PyCon 2010
Peter Baumgartner
pete@lincolnloop.com
Please rate this talk at:
http://spkr8.com/t/4365