### start() Source: https://coverage.readthedocs.io/en/7.14.1/api_coverage.html Starts measuring code coverage. Coverage measurement is only collected in functions called after start() is invoked. Statements in the same scope as start() won’t be measured. ```APIDOC ## start() ### Description Starts measuring code coverage. Coverage measurement is only collected in functions called after `start()` is invoked. Statements in the same scope as `start()` won’t be measured. Once you invoke `start()`, you must also call `stop()` eventually, or your process might not shut down cleanly. The `collect()` method is a context manager to handle both starting and stopping collection. ### Return type None ``` -------------------------------- ### Install Coverage.py Source: https://coverage.readthedocs.io/en/stable Install coverage.py using pip. ```bash $ python3 -m pip install coverage ``` -------------------------------- ### Install a Coverage.py Plug-in Package Source: https://coverage.readthedocs.io/en/7.14.1/plugins.html Install the plug-in's package using pip. This is the first step to using a third-party plug-in. ```bash $ python3 -m pip install something ``` -------------------------------- ### coverage.process_startup Source: https://coverage.readthedocs.io/en/7.14.1/api_module.html Starts coverage measurement automatically when Python starts, based on environment variables. ```APIDOC ## Starting coverage.py automatically ### Description This function is used to start coverage measurement automatically when Python starts. See Managing processes for details. ### `coverage.process_startup(_*_ , _force =False_, _slug ='default'_) Call this at Python start-up to perhaps measure coverage. Coverage is started if one of these environment variables is defined: * COVERAGE_PROCESS_START: the config file to use. * COVERAGE_PROCESS_CONFIG: the config data to use, a string produced by CoverageConfig.serialize, prefixed by ":data:". If one of these is defined, it’s used to get the coverage configuration, and coverage is started. For details, see https://coverage.readthedocs.io/en/latest/subprocess.html. Returns the `Coverage` instance that was started, or None if it was not started by this call. ### Parameters: * **force** (_bool_) * **slug** (_str_) ### Return Type: _Coverage_ | None ``` -------------------------------- ### Install Development and Compiler Tools (Debian/Ubuntu) Source: https://coverage.readthedocs.io/en/7.14.1/install.html On Debian-based systems like Ubuntu, install python-dev and gcc before installing Coverage.py if the C extension is missing. ```bash $ sudo apt-get install python-dev gcc ``` ```bash $ sudo apt-get install python3-dev gcc ``` -------------------------------- ### read Source: https://coverage.readthedocs.io/en/7.14.1/api_coveragedata.html Starts using an existing coverage data file. ```APIDOC ## read() ### Description Start using an existing data file. ### Return type None ``` -------------------------------- ### Install Development and Compiler Tools (RHEL/CentOS/Fedora) Source: https://coverage.readthedocs.io/en/7.14.1/install.html On RHEL-based systems like CentOS or Fedora, install python-devel and gcc before installing Coverage.py if the C extension is missing. ```bash $ sudo yum install python-devel gcc ``` ```bash $ sudo yum install python3-devel gcc ``` -------------------------------- ### Check Coverage.py Installation via Module Source: https://coverage.readthedocs.io/en/7.14.1/install.html Verify Coverage.py installation by invoking it as a Python module. This confirms the installation and C extension status. ```bash $ python3 -m coverage --version Coverage.py, version 7.14.1 with C extension Documentation at https://coverage.readthedocs.io/en/7.14.1 ``` -------------------------------- ### Starting Coverage Measurement Source: https://coverage.readthedocs.io/en/7.14.1/api_coverage.html Invoke start() to begin measuring code coverage. Coverage is only collected for code executed after start() is called. Ensure stop() is called eventually. ```python cov.start() ``` -------------------------------- ### For Loop Example Source: https://coverage.readthedocs.io/en/7.14.1/branch.html Demonstrates a basic for loop and its branches. Coverage reports missing branches when a path is not taken. ```Python 1items = [1] # or empty, see the explanations 2for x in items: 3 print(x) 4 if x: 5 print("x is true") 6print("done") ``` ```text Missing: 3-5 ``` ```text Missing: 4->2 ``` -------------------------------- ### Configuring Coverage for Subprocesses with .pth file Source: https://coverage.readthedocs.io/en/7.14.1/subprocess.html To automatically start coverage measurement in all Python processes, create a `.pth` file in your Python installation directory that imports and calls `coverage.process_startup()`. ```python import coverage; coverage.process_startup() ``` -------------------------------- ### Partial INI Configuration for Coverage.py Source: https://coverage.readthedocs.io/en/7.14.1/config.html A minimal INI configuration example for coverage.py, showing the [run] and [report] sections. ```ini # You can also use sections like [tool.coverage.run] [run] branch = true [report] ``` -------------------------------- ### Start Coverage Measurement Automatically Source: https://coverage.readthedocs.io/en/7.14.1/api_module.html Call this function at Python startup to automatically start coverage measurement. Coverage is initiated if specific environment variables (COVERAGE_PROCESS_START or COVERAGE_PROCESS_CONFIG) are defined. Returns the Coverage instance or None. ```python import coverage coverage_instance = coverage.process_startup() if coverage_instance: print("Coverage started") else: print("Coverage not started") ``` -------------------------------- ### Install development requirements for coverage.py Source: https://coverage.readthedocs.io/en/7.14.1/contributing.html Install the necessary development requirements for coverage.py using either the make command or pip with the dev.pip file. You might need to upgrade pip first. ```bash $ make install ``` ```bash $ python3 -m pip install -r requirements/dev.pip ``` -------------------------------- ### Display Coverage.py Version Information Source: https://coverage.readthedocs.io/en/7.14.1/commands/index.html Show the installed version of coverage.py and its documentation URL. This is useful for verifying the installation and checking compatibility. ```bash $ coverage --version Coverage.py, version 7.14.1 with C extension Documentation at https://coverage.readthedocs.io/en/7.14.1 ``` -------------------------------- ### While Loop Example Source: https://coverage.readthedocs.io/en/7.14.1/branch.html Shows a while loop with conditional branching. The example highlights how unexecuted branches, like the false path of an if statement within the loop, are reported as missing. ```Python 1condition = True 2flag = True 3while condition: 4 do_something = True 5 if flag: 6 condition = False 7print("done") ``` ```text Missing: 5->3 ``` -------------------------------- ### Annotated Source Code Example Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_annotate.html Illustrates the output format of the 'annotate' command, showing line prefixes for executed, missing, and excluded statements. ```text > executed ! missing (not executed) - excluded ``` ```python # A simple function, never called with x==1 > def h(x): """Silly function.""" - if 0: # pragma: no cover - pass > if x == 1: ! a = 1 > else: > a = 2 ``` -------------------------------- ### Check Coverage.py Version and C Extension Source: https://coverage.readthedocs.io/en/7.14.1/install.html Verify that Coverage.py is installed and if the C extension is enabled by checking the version output. ```bash $ coverage --version Coverage.py, version 7.14.1 with C extension Documentation at https://coverage.readthedocs.io/en/7.14.1 ``` -------------------------------- ### Start using an existing data file Source: https://coverage.readthedocs.io/en/7.14.1/api_coveragedata.html Initiates the use of an existing coverage data file. This method reads data from the file into the CoverageData object. ```python cd.read() ``` -------------------------------- ### Coverage Class Basic Usage Source: https://coverage.readthedocs.io/en/7.14.1/api.html Demonstrates the basic workflow of using the `coverage.Coverage` class to start, stop, save, and report coverage data. ```APIDOC ## Coverage Class Basic Usage ### Description This example shows the fundamental steps to instrument code execution, collect coverage data, and generate a report using the `coverage.Coverage` class. ### Method Programmatic API calls ### Endpoint N/A (Programmatic) ### Parameters N/A ### Request Example ```python import coverage cov = coverage.Coverage() cov.start() # .. call your code .. cov.stop() cov.save() cov.html_report() ``` ### Response N/A (Programmatic execution) ### Error Handling Methods can raise specialized exceptions described in Coverage exceptions. ``` -------------------------------- ### XML Report with File Paths Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_xml.html Example of how to configure coverage.py to include complete file paths in the XML report using the 'include' setting in .coveragerc. ```ini [run] include = foo/* bar/* ``` -------------------------------- ### TOML Path Configuration Source: https://coverage.readthedocs.io/en/7.14.1/config.html Example of configuring path mappings in TOML format for coverage.py. This helps in combining data from different source locations. ```toml [paths] source = [ "src/", "/jenkins/build/*/src", "c:\\myproj\\src", ] ``` -------------------------------- ### Get Help for Coverage.py Commands Source: https://coverage.readthedocs.io/en/7.14.1/commands/index.html Display help information for the coverage.py tool or specific commands. Use 'coverage help' for general help or 'coverage help ' for command-specific details. ```bash $ coverage help $ coverage help run $ coverage run --help ``` -------------------------------- ### collect() Source: https://coverage.readthedocs.io/en/7.14.1/api_coverage.html A context manager to start and stop coverage measurement collection. ```APIDOC ## collect() ### Description A context manager to start/stop coverage measurement collection. Added in version 7.3. ### Return type _Iterator_[None] ``` -------------------------------- ### Registering a Custom Coverage.py Plugin Source: https://coverage.readthedocs.io/en/7.14.1/api_plugin.html Example of how to define a custom plugin class and register it using the coverage_init function. This pattern is used for various plugin types. ```python import coverage class MyPlugin(coverage.CoveragePlugin): ... def coverage_init(reg, options): reg.add_file_tracer(MyPlugin()) ``` -------------------------------- ### INI Path Configuration Source: https://coverage.readthedocs.io/en/7.14.1/config.html Example of configuring path mappings in INI format for coverage.py. This is an alternative to TOML for specifying source file locations. ```ini [coverage:paths] source = src/ /jenkins/build/*/src c:\myproj\src ``` -------------------------------- ### Basic Programmatic Usage of Coverage.py Source: https://coverage.readthedocs.io/en/7.14.1/api.html This snippet demonstrates the fundamental steps to use Coverage.py programmatically: initializing the Coverage object, starting and stopping measurement, saving the data, and generating an HTML report. ```python import coverage cov = coverage.Coverage() cov.start() # .. call your code .. cov.stop() cov.save() cov.html_report() ``` -------------------------------- ### Run Python 3.10 Tests with Tox Source: https://coverage.readthedocs.io/en/7.14.1/contributing.html Execute tests for Python 3.10 using tox. This command installs dependencies and runs the test suite, showing progress and final results. ```bash % python3 -m tox -e py310 py310: pip-26.0.1-py3-none-any.whl already present in /Users/ned/.cache/virtualenv/wheel/3.10/embed/3/pip.json py310: setuptools-82.0.1-py3-none-any.whl already present in /Users/ned/.cache/virtualenv/wheel/3.10/embed/3/setuptools.json py310: install_deps> python -m pip install -U -r requirements/pip.pip -r requirements/pytest.pip -r requirements/light-threads.pip .pkg: install_requires> python -I -m pip install setuptools .pkg: _optional_hooks> python /Users/ned/coverage/trunk/.venv/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta .pkg: get_requires_for-build_sdist> python /Users/ned/coverage/trunk/.venv/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta .pkg: get_requires_for_build_wheel> python /Users/ned/coverage/trunk/.venv/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta .pkg: prepare_metadata_for_build_wheel> python /Users/ned/coverage/trunk/.venv/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta .pkg: build_sdist> python /Users/ned/coverage/trunk/.venv/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta py310: install_package_deps> python -m pip install -U 'tomli; python_full_version <= "3.11.0a6"' py310: install_package> python -m pip install -U --force-reinstall --no-deps .tox/.tmp/package/1/coverage-7.13.5a0.dev1.tar.gz py310: commands[0]> python igor.py zip_mods py310: commands[1]> python setup.py --quiet build_ext --inplace py310: commands[2]> python -m pip install -q -e . py310: commands[3]> python igor.py clean_for_core ctrace py310: commands[4]> python igor.py test_with_core ctrace === CPython 3.10.20 (main Mar 3 2026 05:34:05) (gil) with C tracer (/usr/local/pyenv/pyenv/versions/3.10.20) === bringing up nodes... ....................................................................................... [ 5%] ...................................................................................s... [ 10%] ......................................................................................s [ 16%] .................................................................s....s................ [ 21%] ....................................................................................... [ 27%] ..............s........................................................................ [ 32%] ....................................................................................... [ 38%] ....................................................................................... [ 43%] ....................................................................................... [ 49%] ....................................................................................... [ 54%] ...............................................s............s.......................... [ 60%] ....................................................................................... [ 65%] ..............................s........................................................ [ 71%] .........................................s............................................. [ 76%] ..........s...........................s.......s.s..s.............................s..... [ 82%] ...............s.......................................s............................... [ 87%] ....................................................................................... [ 93%] ...................................................................................s... [ 98%] ................ [100%] 1564 passed, 18 skipped in 17.78s py310: commands[5]> python igor.py clean_for_core pytrace py310: commands[6]> python igor.py test_with_core pytrace === CPython 3.10.20 (main Mar 3 2026 05:34:05) (gil) with Python tracer (/usr/local/pyenv/pyenv/versions/3.10.20) === bringing up nodes... ....................................................................................... [ 5%] ..................................................................................s.... [ 10%] .................................................................................s..... [ 16%] .......................................................s..s...s.ss.ss.s.s.............. [ 21%] ...s................................................................................... [ 27%] ...........s........................................................................... [ 32%] .................................................................................s..... [ 38%] ............................................s.......................................... [ 43%] ....................................................................................... [ 49%] ``` -------------------------------- ### Coverage Measurement with Context Manager Source: https://coverage.readthedocs.io/en/7.14.1/api_coverage.html This snippet demonstrates using the Coverage class as a context manager, which automatically handles starting and stopping coverage measurement. This is a more concise way to manage coverage for a block of code. ```python cov = Coverage() with cov.collect(): #.. call your code .. cov.html_report(directory="covhtml") ``` -------------------------------- ### dynamic_context Source: https://coverage.readthedocs.io/en/7.14.1/api_plugin.html Get the dynamically computed context label for a given frame. This method is invoked for each frame when outside of a dynamic context, to see if a new dynamic context should be started. If it returns a string, a new context label is set for this and deeper frames. ```APIDOC ## dynamic_context(_frame_) ### Description Get the dynamically computed context label for frame. Plug-in type: dynamic context. This method is invoked for each frame when outside of a dynamic context, to see if a new dynamic context should be started. If it returns a string, a new context label is set for this and deeper frames. The dynamic context ends when this frame returns. ### Parameters * **frame** (_FrameType_) - The current execution frame. ### Return Type str | None - A string to start a new dynamic context, or None if no new context should be started. ``` -------------------------------- ### Configure Static Context via setup.cfg or tox.ini Source: https://coverage.readthedocs.io/en/7.14.1/contexts.html Set a static context for the entire coverage run using setup.cfg or tox.ini configuration files. ```ini [coverage:run] dynamic_context = test_function ``` -------------------------------- ### Display Help for `coverage html` Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_html.html Shows the available options and usage for the `coverage html` command. This is useful for understanding all configuration possibilities. ```bash $ coverage html --help ``` -------------------------------- ### Coverage XML Command Help Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_xml.html Displays help information for the 'coverage xml' command, outlining its usage and available options. ```bash $ coverage xml --help Usage: coverage xml [options] [modules] Generate an XML report of coverage results. Options: --data-file=INFILE Read coverage data for report generation from this file. Defaults to '.coverage'. [env: COVERAGE_FILE] --fail-under=MIN Exit with a status of 2 if the total coverage is less than MIN. -i, --ignore-errors Ignore errors while reading source files. --include=PAT1,PAT2,... Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -o OUTFILE Write the XML report to this file. Defaults to 'coverage.xml' -q, --quiet Don't print messages about what is happening. --skip-empty Skip files with no code. --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] ``` -------------------------------- ### Configure source paths for coverage measurement Source: https://coverage.readthedocs.io/en/7.14.1/config.html Use the `source` option in the `[tool.coverage.paths]` section to specify directories or packages for coverage measurement. This example shows how to define multiple source paths, including absolute and relative paths, and paths with wildcards. ```TOML [tool.coverage.paths] source = [ "src/", "/jenkins/build/*/src", "c:\\myproj\\src", ] ``` -------------------------------- ### Display coverage run help Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_run.html Show the help message for the 'coverage run' command, listing all available options and their descriptions. ```bash $ coverage run --help Usage: coverage run [options] [program options] Run a Python program, measuring code execution. Options: -a, --append Append data to the data file. Otherwise it starts clean each time. --branch Measure branch coverage in addition to statement coverage. --concurrency=LIBS Properly measure code using a concurrency library. Valid values are: eventlet, gevent, greenlet, multiprocessing, thread, or a comma-list of them. --context=LABEL The context label to record for this coverage run. --data-file=OUTFILE Write the recorded coverage data to this file. Defaults to '.coverage'. [env: COVERAGE_FILE] --include=PAT1,PAT2,... Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -m, --module is an importable Python module, not a script path, to be run as 'python -m' would run it. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -L, --pylib Measure coverage even inside the Python installed library, which isn't done by default. -p, --parallel-mode Append a unique suffix to the data file name to collect separate data from multiple processes. --save-signal=SIGNAL Specify a signal that will trigger coverage to write its collected data. Supported values are: USR1, USR2. Not available on Windows. --source=SRC1,SRC2,... A list of directories or importable names of code to measure. --timid Use the slower Python trace function core. --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] ``` -------------------------------- ### classmethod current() Source: https://coverage.readthedocs.io/en/7.14.1/api_coverage.html Retrieves the most recently started Coverage instance. Returns None if no instance is active. ```APIDOC ## classmethod current() ### Description Get the latest started Coverage instance, if any. ### Returns A Coverage instance, or None. ``` -------------------------------- ### Get measured contexts Source: https://coverage.readthedocs.io/en/7.14.1/api_coveragedata.html Returns a set of all context names that have been measured. Available since version 5.0. ```python cd.measured_contexts() ``` -------------------------------- ### Get Coverage.py Version Info Source: https://coverage.readthedocs.io/en/7.14.1/api_module.html Access the version information of the Coverage.py library. This is a tuple similar to sys.version_info. ```python import coverage print(coverage.version_info) ``` -------------------------------- ### Configure Plug-in Options in pyproject.toml Source: https://coverage.readthedocs.io/en/7.14.1/plugins.html Provide custom configuration options for a plug-in by creating a section named after the plug-in in pyproject.toml. ```toml [tool.coverage.something.plugin] option1 = true option2 = "abc.foo" ``` -------------------------------- ### Get the data filename Source: https://coverage.readthedocs.io/en/7.14.1/api_coveragedata.html Returns the path to the file where coverage data is stored. Available since version 5.0. ```python cd.data_filename() ``` -------------------------------- ### If/Else Statement Example Source: https://coverage.readthedocs.io/en/7.14.1/branch.html Illustrates an if/else statement where one branch is always taken. The unexecuted branch is reported as missing. ```Python 1flag = True 2if flag: 3 do_true() 4else: 5 do_false() ``` ```text Missing: 2->5 ``` -------------------------------- ### Get measured files Source: https://coverage.readthedocs.io/en/7.14.1/api_coveragedata.html Returns a set of all filenames that have been measured. A file may be included even if no lines or arcs were recorded for it. ```python cd.measured_files() ``` -------------------------------- ### Run Unittest with Coverage Source: https://coverage.readthedocs.io/en/stable Execute unittest discover tests under coverage measurement by prefixing the command with 'coverage run -m'. ```bash $ coverage run -m unittest discover ``` -------------------------------- ### Get the base filename Source: https://coverage.readthedocs.io/en/7.14.1/api_coveragedata.html Returns the base filename used for storing coverage data. Available since version 5.0. ```python cd.base_filename() ``` -------------------------------- ### sys_info Source: https://coverage.readthedocs.io/en/7.14.1/api_plugin.html Get a list of information useful for debugging. This method will be invoked for `--debug=sys`. Your plug-in can return any information it wants to be displayed. ```APIDOC ## sys_info() ### Description Get a list of information useful for debugging. Plug-in type: any. This method will be invoked for `--debug=sys`. Your plug-in can return any information it wants to be displayed. ### Return Type _Iterable_[tuple[str, _Any_]] - A list of pairs: [(name, value), …]. ``` -------------------------------- ### Switching Dynamic Context Source: https://coverage.readthedocs.io/en/7.14.1/api_coverage.html Use switch_context() to change the dynamic context label during coverage collection. This requires that coverage measurement has already been started. ```python cov.switch_context("new_context") ``` -------------------------------- ### Coverage Combine Command Help Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_combine.html Display the help message for the 'coverage combine' command to understand its usage, options, and arguments. ```bash $ coverage combine --help ``` -------------------------------- ### Coverage Annotate Command Help Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_annotate.html Displays the help message for the 'coverage annotate' command, outlining its usage and available options. ```bash $ coverage annotate --help Usage: coverage annotate [options] [modules] Make annotated copies of the given files, marking statements that are executed with > and statements that are missed with !. Options: -d DIR, --directory=DIR Write the output files to DIR. --data-file=INFILE Read coverage data for report generation from this file. Defaults to '.coverage'. [env: COVERAGE_FILE] -i, --ignore-errors Ignore errors while reading source files. --include=PAT1,PAT2,... Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] ``` -------------------------------- ### Configure Static Context via .coveragerc (Alternative Section) Source: https://coverage.readthedocs.io/en/7.14.1/contexts.html Set a static context for the entire coverage run using an alternative section in the .coveragerc configuration file. ```ini # You can also use sections like [tool.coverage.run] [run] dynamic_context = "test_function" ``` -------------------------------- ### XML Report with File Names Only Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_xml.html Example of the default behavior where only file names are included in the XML report when using the 'source' setting in .coveragerc. ```ini [run] source = foo bar ``` -------------------------------- ### Configure Plug-in in .coveragerc (TOML format with section) Source: https://coverage.readthedocs.io/en/7.14.1/plugins.html Configure coverage.py to use a plug-in using the [tool.coverage.run] section in a TOML file, similar to pyproject.toml. ```toml # You can also use sections like [tool.coverage.run] [run] plugins = [ "something.plugin" ] ``` -------------------------------- ### dynamic_source_filename(_filename_, _frame_) Source: https://coverage.readthedocs.io/en/7.14.1/api_plugin.html Gets a dynamically computed source file name for a given frame. This method is only invoked if `has_dynamic_source_filename()` returns True. ```APIDOC ## dynamic_source_filename(_filename_, _frame_) Get a dynamically computed source file name. Some plug-ins need to compute the source file name dynamically for each frame. This function will not be invoked if `has_dynamic_source_filename()` returns False. Returns the source file name for this frame, or None if this frame shouldn’t be measured. Parameters: * **filename** (_str_) * **frame** (_FrameType_) Return type: str | None ``` -------------------------------- ### Run Linting Source: https://coverage.readthedocs.io/en/7.14.1/contributing.html Execute the linting process using make lint. This command checks for code quality issues. ```bash $ make lint ``` -------------------------------- ### Get Coverage.py Version String Source: https://coverage.readthedocs.io/en/7.14.1/api_module.html Retrieve the version of Coverage.py as a string, which may include release level indicators like 'b2' for beta. ```python import coverage print(coverage.__version__) ``` -------------------------------- ### Run a Python module with coverage Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_run.html Execute a Python module as a script using the '-m' switch and collect coverage data. Arguments are passed to the module. ```bash $ coverage run -m packagename.modulename arg1 arg2 blah blah ..your program's output.. blah blah ``` -------------------------------- ### Example of a partial branch in Python Source: https://coverage.readthedocs.io/en/7.14.1/branch.html This code demonstrates a partial branch scenario where an if statement's condition is never false, leading to an unvisited branch. ```python 1def my_partial_fn(x): 2 if x: 3 y = 10 4 return y 5 6my_partial_fn(1) ``` -------------------------------- ### Coverage JSON Command Help Source: https://coverage.readthedocs.io/en/7.14.1/commands/cmd_json.html Displays the help message for the `coverage json` command, outlining its usage and available options. This is useful for understanding the command's capabilities and parameters. ```bash $ coverage json --help Usage: coverage json [options] [modules] Generate a JSON report of coverage results. Options: --contexts=REGEX1,REGEX2,... Only display data from lines covered in the given contexts. Accepts Python regexes, which must be quoted. --data-file=INFILE Read coverage data for report generation from this file. Defaults to '.coverage'. [env: COVERAGE_FILE] --fail-under=MIN Exit with a status of 2 if the total coverage is less than MIN. -i, --ignore-errors Ignore errors while reading source files. --include=PAT1,PAT2,... Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -o OUTFILE Write the JSON report to this file. Defaults to 'coverage.json' --pretty-print Format the JSON for human readers. -q, --quiet Don't print messages about what is happening. --show-contexts Show contexts for covered lines. --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] ``` -------------------------------- ### file_reporter Source: https://coverage.readthedocs.io/en/7.14.1/api_plugin.html Get the FileReporter class to use for a file. This method is invoked only if `file_tracer()` returns a non-None value for the given filename. It is an error to return None from this method. ```APIDOC ## file_reporter(_filename_) ### Description Get the `FileReporter` class to use for a file. Plug-in type: file tracer. This will only be invoked if filename returns non-None from `file_tracer()`. It’s an error to return None from this method. ### Parameters * **filename** (_str_) - The path to the file. ### Return Type `FileReporter` | str - A `FileReporter` object to use to report on filename, or the string "python" to have coverage.py treat the file as Python. ``` -------------------------------- ### Configure Static Context via pyproject.toml Source: https://coverage.readthedocs.io/en/7.14.1/contexts.html Set a static context for the entire coverage run using the pyproject.toml configuration file. ```toml [tool.coverage.run] dynamic_context = "test_function" ``` -------------------------------- ### file_tracer Source: https://coverage.readthedocs.io/en/7.14.1/api_coveragedata.html Gets the plugin name of the file tracer for a given file. Returns the plugin name, an empty string if no plugin was used, or None if the file was not measured. ```APIDOC ## file_tracer(filename) ### Description Get the plugin name of the file tracer for a file. Returns the name of the plugin that handles this file. If the file was measured, but didn’t use a plugin, then "" is returned. If the file was not measured, then None is returned. ### Parameters * **filename** (str) - The name of the file. ### Return type str | None ``` -------------------------------- ### Enable Branch Coverage Measurement Source: https://coverage.readthedocs.io/en/7.14.1/branch.html Run coverage.py with the --branch flag to enable branch coverage measurement. This flag should be used with the 'run' command. ```bash coverage run --branch myprog.py ```