Versions Compared

Key

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

Table of Contents

Coverage.py

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.

Prepare

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

Build

Coverage.py doesn't require any special treatment during the preparation of the build.

Execute

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
languagebash
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
languagebash
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.

Coverage

Report

Example