PyCharm 2022.2 Help

Configuring code coverage measurement

PyCharm makes it possible to configure the various aspects of code coverage measurement.

Configure code coverage behavior

  1. Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Coverage.

  2. Define how the collected coverage data will be processed:

    • Show options before applying coverage to the editor: show the Code Coverage dialog every time you run a new run configuration with code coverage.

    • Do not apply collected coverage: discard the new code coverage results.

    • Replace active suites with the new one: discard the active suites and use the new one every time you launch a new run configuration with code coverage.

    • Add to the active suites: add new code coverage suites to the active suites every time you launch a new run configuration with code coverage.

  3. Select the Activate Coverage View checkbox to open the Coverage tool window automatically.

  4. Select the Use bundled coverage.py checkbox to specify which of the coverage tools you want to use - the one bundled with PyCharm, or included in the active Python interpreter. By default, this checkbox is not selected, and PyCharm uses coverage that is installed on the Python interpreter.

  5. Select the Branch coverage checkbox to specify whether you want to use the branch coverage.

    Thus additional information to the pure line coverage reports is added, marking the coverage of lines with conditional statements as incomplete in case one or more branches haven’t been executed.

    coverage branch

    For more information, see this page.

Change colors of the coverage highlighting

  1. Press Ctrl+Alt+S to open the IDE settings and select Editor | Color Scheme | General.

  2. Alternatively, click the Edit Coverage Colors button in the popup that opens on clicking the coverage indication line in the gutter.

  3. In the list of components, expand the Line Coverage node and select a type of coverage: for example, Full, Partial or Uncovered.

  4. Click the Foreground field to open the Select Color dialog.

  5. Select a color, apply the changes, and close the dialog.

Configure code coverage colors
Last modified: 17 March 2022