Search code examples
pythoncontinuous-integrationhudsoncode-coveragecobertura

Hudson "Source code is unavailable."


I'm using Hudson to continuously build a Python project. Unit tests and code coverage work great, but this message appears when drilling into the Cobertura Coverage Report for my files that are not unit tests:

Source code is unavailable.Some possible reasons are:

* This is not the most recent build (to save on disk space, this plugin only keeps the most recent builds source code).
* Cobertura found the source code but did not provide enough information to locate the source code.
* Cobertura could not find the source code, so this plugin has no hope of finding it.

The strange thing is that the source code for the unit tests are found and displayed. I tried to manually copy the source files for other .py files into ~/.hudson/jobs/<projectname>/cobertura (where the unit tests get copied), but it did not work.

Any suggestions?


Solution

  • This is one hell of an ugly hack, but its the only thing that I could come up with to finally make it work... and after hours of Googling and hacking away trying to get results, this is the only thing I came up with.

    coverage run manage.py test
    coverage xml
    sed 's/filename="/filename="my\/path\//g' coverage.xml > coverage2.xml
    

    This is just relpacing the filename attribute of the class xml tags and adding the full path to the source files at the beginning. Just make sure that you update the Cobertura xml report pattern to be coverage2.xml (if that is where you're piping sed's output to).

    It would be nice if the Cobertura plugin would allow you to enter the source path similar to how the Violations plugin does - unfortunately, as far as I'm aware, it doesn't.

    I hope this helps!