Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Maven and Ant can also be used to launch analysis on Python projects.

Advanced Settings

 

Info

The features "Execution of unit tests" and "Coverage metrics" and thus the settings "sonar.python.xunit.reportPath" and "sonar.python.coverage.*" will be available in Sonar Python 1.1 (version currently in development)

Property

Scope

Example

Description

sonar.python.pylintSystem-wide/usr/local/bin/pylint

Path to the pylint executable to use in pylint analysis. Set to empty to use the default one.

It has to be set on Windows, use either masked backslashes or slashes as path separators; examples: C:\\Python26\\Scripts\\pylint.bat or C:/Python/26/Scripts/pylint.bat

sonar.python.pylint_configProject-wide.pylintrc

Path to the pylint configuration file (relative to project root or absolute) to use in pylint analysis. Set to empty to use the default.

sonar.python.xunit.reportPathProject-widenosetests.xmlAnt pattern describing the path to unit test execution reports, relative to projects root. Leave unset to use the default ("xunit-reports/xunit-result-*.xml"). The reports have to conform to the junitreport XML format.
sonar.python.coverage.reportPathProject-widecoverage.xmlAnt pattern describing the path to coverage reports, relative to projects root. Leave unset to use the default ("coverage-reports/coverage-*.xml"). The reports have to conform to the Cobertura XML format.
sonar.python.coverage.itReportPathProject-wideit-coverage.xmlAnt pattern describing the path to coverage reports for integration tests, relative to projects root. Leave unset to use the default ("coverage-reports/it-coverage-*.xml"). The reports have to conform to the Cobertura XML format.

Make sure to set up the environment properly (PYTHONPATH etc.) before running the analyzer, if your project requires it.

External report generation

Here is a quick guide how to generate the reports using external tools.

Test execution

No Format
nosetests --with-xunit [tests to execute]

To get a more accurate execution time statistics make sure to use nose 1.1.0 or newer.

Coverage

Use Ned Batchelders coverage package like this:

No Format
coverage erase
coverage run --branch --sources=<python packages> <program> 
coverage xml -i

Make sure to put all packages to measure into the --source parameter. That ensures that coverage will report zero coverage on all untouched files, as you most probably want to. To make this work, make sure to meet two prerequisites:

  • use coverage => 3.4
  • the packages should be packages, i.e. every directory on the way to the sources should contain an __init__.py file.

Extending Coding Rules using XPath

New coding rules can be added using XPath. See the related documentation.

To navigate the AST, download the SSLR Python Toolkit.

Change Log

JIRA Issues
anonymoustrue
titleVersion 1.1
renderModestatic
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=18716&pid=11911&sorter/field=priority&sorter/order=DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleVersion 1.0
renderModestatic
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=18636&pid=11911&sorter/field=priority&sorter/order=DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleVersion 0.1
renderModestatic
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=18078&pid=11911&sorter/field=priority&sorter/order=DESC&tempMax=1000