Information
We are currently investigating an issue with the editor of some pages. Please save your work and avoid to create new pages until this banner is gone.
Table of Contents |
---|
Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.
It is recommended to have a configuration file for coverage.py. Starting with 2022OCT, ACS brings its own configuration file in '$ACSROOT/config/.coveragerc'. An example of this configuration is as follows:
Code Block |
---|
[run]
disable_warnings = no-data-collected,module-not-imported
omit = */sitecustomize.py |
Coverage.py doesn't require any special treatment during the preparation of the build.
For the execution, we need to use a special program instead of python and pass the path to the configuration file. For instance:
Code Block | ||
---|---|---|
| ||
coverage run --rcfile $ACSROOT/config/.coveragerc --source $ACSROOT/${PYTHON_SITE_PACKAGES} -p <usual_command> |
If you're using programs such as nose or nose2 to run your tests, then execute like this:
Code Block |
---|
coverage run --rcfile $ACSROOT/config/.coveragerc --source $ACSROOT/${PYTHON_SITE_PACKAGES} -p -m <usual_command> |
If you're trying to do coverage for an inlined command (python -c "..."), then you could do something like this:
Code Block | ||
---|---|---|
| ||
script=/tmp/coverage_cmd.$RANDOM.py
echo "<inlined_python_code>" > $script
coverage run --rcfile $ACSROOT/config/.coveragerc --source $ACSROOT/${PYTHON_SITE_PACKAGES} -p $script |
There's a wrapper in 'ACS/LGPL/acsBUILD/src/coverage_wrapper.sh' which takes care of any of these scenarios, but is non-trivial to setup because it has to impersonate 'python' once.