PyCharm 2024.3 Help

Running with coverage

PyCharm provides a dedicated action for performing run with the code coverage measurement. The code coverage data is processed according to the option selected on the Coverage page of the Settings dialog (Ctrl+Alt+S) .

Run tests with coverage using an existing configuration

To run tests with coverage using a previously created run configuration, do one of the following:

  • Press Alt+Shift+F10 to open the Run popup, select the required configuration, click to the right of it, and then select Cover.

    Run with Coverage using popup
  • From the toolbar, select the required run configuration from the configurations list, click to expand its options and select Run '<configuration name>' with Coverage.

    Run with Coverage

Run tests with coverage from the Project view

To run a test or multiple tests with coverage from the Project view, do the following:

  1. Right-click a specific test file or a directory containing the required tests.

  2. From the context menu, select the corresponding run command Run '<name>' with Coverage.

    Run with Coverage from the Project view

Run tests with coverage from the editor

  • Click Run in the gutter next to the required test class or method and from the context menu that opens, select Run '<name>' with Coverage.

    Run a specific test

If the Show options before applying coverage to the editor checkbox has been selected in Settings Ctrl+Alt+S | Build, Execution, Deployment | Coverage, a dialog appears where you can choose whether you want to replace the active coverage suites, add the collected data to the active suites, or not apply coverage data. You can also opt to skip this dialog in the future. In case any other option has been selected, the respective action will be performed silently.

Options before applying coverage to the editor

Now you can explore the collected coverage data in the Coverage tool window, the Project tool window, and in the editor.

Hide coverage results

  • To hide coverage results, you can do the following:

    • Close a tab with coverage statistics in the Coverage tool window.

      Coverage tool window
    • Click a coverage highlighting in a gutter and select Hide coverage.

      Hide coverage
Last modified: 08 October 2024