sdkagent

coveragepy API reference

400 public APIs from coveragepy (coveragepy/coveragepy) — 70 classes, 125 functions, 205 methods. Signatures extracted by static analysis of the actual source.

Repository: coveragepy/coveragepy

KindCount
Classes70
Functions125
Methods205

API list

classcoverage.annotate.AnnotateReporter
Generate annotated source files showing line coverage.
methodcoverage.annotate.AnnotateReporter.annotate_file(fr:FileReporter, analysis:Analysis) -> None
Annotate a single file.
methodcoverage.annotate.AnnotateReporter.report(morfs:TMorfs, directory:str | None=None) -> None
Run the report.
classcoverage.bytecode.ByteParser
Parse bytecode to understand the structure of code.
methodcoverage.bytecode.ByteParser.code_objects() -> Iterable[CodeType]
Iterate over all the code objects in `code`.
methodcoverage.bytecode.ByteParser.find_statements() -> Iterable[TLineNo]
Find the statements in `self.code`.
funccoverage.bytecode.bytes_to_lines(code:CodeType) -> dict[TOffset, TLineNo]
Make a dict mapping byte code offsets to line numbers.
funccoverage.bytecode.op_set(*op_names:str) -> set[int]
Make a set of opcodes from instruction names.
classcoverage.cmdline.CmdOptionParser
Parse one of the new-style commands for coverage.py.
classcoverage.cmdline.CoverageOptionParser
Base OptionParser for coverage.py.
methodcoverage.cmdline.CoverageOptionParser.error(msg:str) -> NoReturn
Override optparse.error so sys.exit doesn't get called.
classcoverage.cmdline.CoverageScript
The command-line interface to coverage.py.
methodcoverage.cmdline.CoverageScript.command_line(argv:list[str]) -> int
The bulk of the command line interface to coverage.py.
methodcoverage.cmdline.CoverageScript.do_debug(args:list[str]) -> int
Implementation of 'coverage debug'.
methodcoverage.cmdline.CoverageScript.do_help(options:optparse.Values, args:list[str], parser:optparse.OptionParser) -> bool
Deal with help requests.
methodcoverage.cmdline.CoverageScript.do_run(options:optparse.Values, args:list[str]) -> int
Implementation of 'coverage run'.
methodcoverage.cmdline.CoverageScript.do_signal_save(_signum:int, _frame:types.FrameType | None) -> None
Signal handler to save coverage report
classcoverage.cmdline.MultiParaHelpFormatter
An optparse formatter that allows multi-paragraph help text.
funccoverage.cmdline.main(argv:list[str] | None=None) -> int | None
The main entry point to coverage.py.
funccoverage.cmdline.main_deprecated(argv:list[str] | None=None) -> int | None
For entry points we'll be getting rid of.
funccoverage.cmdline.prep_help(text:str) -> str
Prepare a multi-line string for help to reformat nicely.
funccoverage.cmdline.show_help(error:str | None=None, topic:str | None=None, parser:optparse.OptionParser | None=None) -> None
Display an error message, or the named topic.
funccoverage.cmdline.unglob_args(args:list[str]) -> list[str]
Interpret shell wildcards for platforms that need it.
funccoverage.cmdline.unshell_list(s:str) -> list[str] | None
Turn a command-line argument into a list.
classcoverage.collector.Collector
Collects trace data.
methodcoverage.collector.Collector.cached_mapped_file(filename:str) -> str
A locally cached version of file names mapped through file_mapper.
methodcoverage.collector.Collector.disable_plugin(disposition:TFileDisposition) -> None
Disable the plugin mentioned in `disposition`.
methodcoverage.collector.Collector.flush_data() -> bool
Save the collected data to our associated `CoverageData`.
methodcoverage.collector.Collector.lock_data() -> None
Lock self.data_lock, for use by tracers.
methodcoverage.collector.Collector.mapped_file_dict(d:Mapping[str, T]) -> dict[str, T]
Return a dict like d, but with keys modified by file_mapper.
methodcoverage.collector.Collector.pause() -> None
Pause tracing, but be prepared to `resume`.
methodcoverage.collector.Collector.plugin_was_disabled(plugin:CoveragePlugin) -> None
Record that `plugin` was disabled during the run.
methodcoverage.collector.Collector.post_fork() -> None
After a fork, tracers might need to adjust.
methodcoverage.collector.Collector.reset() -> None
Clear collected data, and prepare to collect more.
methodcoverage.collector.Collector.resume() -> None
Resume tracing after a `pause`.
methodcoverage.collector.Collector.start() -> None
Start collecting trace information.
methodcoverage.collector.Collector.stop() -> None
Stop collecting trace information.
methodcoverage.collector.Collector.switch_context(new_context:str | None) -> None
Switch to a new dynamic context.
methodcoverage.collector.Collector.tracer_name() -> str
Return the class name of the tracer we're using.
methodcoverage.collector.Collector.unlock_data() -> None
Unlock self.data_lock, for use by tracers.
methodcoverage.collector.Collector.use_data(covdata:CoverageData, context:str | None) -> None
Use `covdata` for recording data.
classcoverage.config.CoverageConfig
Coverage.py configuration.
methodcoverage.config.CoverageConfig.copy() -> CoverageConfig
Return a copy of the configuration.
methodcoverage.config.CoverageConfig.deserialize(config_str:str) -> CoverageConfig
Take a string from `serialize`, and make a CoverageConfig.
methodcoverage.config.CoverageConfig.from_args(**kwargs:TConfigValueIn) -> None
Read config values from `kwargs`.
methodcoverage.config.CoverageConfig.from_file(filename:str, warn:Callable[[str], None], our_file:bool) -> bool
Read configuration from a .rc file.
methodcoverage.config.CoverageConfig.get_option(option_name:str) -> TConfigValueOut | None
Get an option from the configuration.
methodcoverage.config.CoverageConfig.get_plugin_options(plugin:str) -> TConfigSectionOut
Get a dictionary of options for the plugin named `plugin`.
methodcoverage.config.CoverageConfig.post_process() -> None
Make final adjustments to settings to make them usable.
methodcoverage.config.CoverageConfig.set_option(option_name:str, value:TConfigValueIn | TConfigSectionIn) -> None
Set an option in the configuration.
classcoverage.config.HandyConfigParser
Our specialization of ConfigParser.
methodcoverage.config.HandyConfigParser.get(section:str, option:str, *args:Any, **kwargs:Any) -> str
Get a value, replacing environment variables also.
methodcoverage.config.HandyConfigParser.get_section(section:str) -> TConfigSectionOut
Get the contents of a section, as a dictionary.
methodcoverage.config.HandyConfigParser.getfile(section:str, option:str) -> str
Fix up a file path setting.
methodcoverage.config.HandyConfigParser.getlist(section:str, option:str) -> list[str]
Read a list of strings.
methodcoverage.config.HandyConfigParser.getregexlist(section:str, option:str) -> list[str]
Read a list of full-line regexes.
methodcoverage.config.HandyConfigParser.read(filenames:Iterable[str], encoding_unused:str | None=None) -> list[str]
Read a file name as UTF-8 configuration data.
methodcoverage.config.HandyConfigParser.real_section(section:str) -> str | None
Get the actual name of a section.
funccoverage.config.abs_path_if_exists(path:str) -> str
os.path.abspath, but only if the path exists.
funccoverage.config.config_files_to_try(config_file:bool | str) -> list[tuple[str, bool, bool]]
What config files should we try to read?
funccoverage.config.process_file_value(path:str) -> str
Make adjustments to a file path to make it usable.
funccoverage.config.process_regexlist(name:str, option:str, values:list[str]) -> list[str]
Check the values in a regex list and keep the non-blank ones.
funccoverage.config.read_coverage_config(config_file:bool | str, warn:Callable[[str], None], **kwargs:TConfigValueIn) -> CoverageConfig
Read the coverage.py configuration.
funccoverage.context.qualname_from_frame(frame:FrameType) -> str | None
Get a qualified name for the code running in `frame`.
funccoverage.context.should_start_context(frame:FrameType) -> str | None
The combiner for multiple context switchers.
funccoverage.context.should_start_context_test_function(frame:FrameType) -> str | None
Is this frame calling a test_* function?
classcoverage.control.Coverage
Programmatic access to coverage.py.
methodcoverage.control.Coverage.analysis2(morf:TMorf) -> tuple[str, list[TLineNo], list[TLineNo], list[TLineNo], str]
Analyze a module.
methodcoverage.control.Coverage.annotate(morfs:TMorfs=None, directory:str | None=None, ignore_errors:bool | None=None, omit:str | list[str] | None=None, include:str | list[str] | None=None, contexts:list[str] | None=None) -> None
Annotate a list of modules.
methodcoverage.control.Coverage.branch_stats(morf:TMorf) -> dict[TLineNo, tuple[int, int]]
Get branch statistics about a module.
methodcoverage.control.Coverage.clear_exclude(which:str='exclude') -> None
Clear the exclude list.
methodcoverage.control.Coverage.current() -> Coverage | None
Get the latest started `Coverage` instance, if any.
methodcoverage.control.Coverage.erase() -> None
Erase previously collected coverage data.
methodcoverage.control.Coverage.exclude(regex:str, which:str='exclude') -> None
Exclude source lines from execution consideration.
methodcoverage.control.Coverage.get_data() -> CoverageData
Get the collected data.
methodcoverage.control.Coverage.get_exclude_list(which:str='exclude') -> list[str]
Return a list of excluded regex strings.
methodcoverage.control.Coverage.get_option(option_name:str) -> TConfigValueOut | None
Get an option from the configuration.
methodcoverage.control.Coverage.load() -> None
Load previously-collected coverage data from the data file.
funccoverage.control.Coverage.plugin_info(plugins:list[Any]) -> list[str]
Make an entry for the sys_info from a list of plug-ins.
methodcoverage.control.Coverage.save() -> None
Save the collected coverage data to the data file.
methodcoverage.control.Coverage.set_option(option_name:str, value:TConfigValueIn | TConfigSectionIn) -> None
Set an option in the configuration.
methodcoverage.control.Coverage.start() -> None
Start measuring code coverage.
methodcoverage.control.Coverage.stop() -> None
Stop measuring code coverage.
methodcoverage.control.Coverage.switch_context(new_context:str) -> None
Switch to a new dynamic context.
funccoverage.control.override_config(cov:Coverage, **kwargs:TConfigValueIn) -> Iterator[None]
Temporarily tweak the configuration of `cov`.
funccoverage.control.process_startup(*force:bool=False, *slug:str='default') -> Coverage | None
Call this at Python start-up to perhaps measure coverage.
classcoverage.data.DataFileClassifier
Track what files to combine and which to skip.
methodcoverage.data.DataFileClassifier.classify(f:str) -> Literal['combine', 'skip']
Determine whether to combine or skip this file.
funccoverage.data.add_data_to_hash(data:CoverageData, filename:str, hasher:Hasher) -> None
Contribute `filename`'s data to the `hasher`.
funccoverage.data.combinable_files(data_file:str, data_paths:Iterable[str] | None=None) -> list[str]
Make a list of data files to be combined.
funccoverage.data.debug_data_file(filename:str) -> None
Implementation of 'coverage debug data'.
funccoverage.data.hash_for_data_file(dbfilename:str) -> str
Get the hash of the data in the file.
funccoverage.data.line_counts(data:CoverageData, fullpath:bool=False) -> dict[str, int]
Return a dict summarizing the line coverage data.
funccoverage.data.sorted_lines(data:CoverageData, filename:str) -> list[int]
Get the sorted lines for a file, for tests.
classcoverage.debug.CwdTracker
A class to add cwd info to debug messages.
methodcoverage.debug.CwdTracker.filter(text:str) -> str
Add a cwd message for each new cwd.
classcoverage.debug.DebugControl
Control and output for debugging.
methodcoverage.debug.DebugControl.should(option:str) -> bool
Decide whether to output debug information in category `option`.
methodcoverage.debug.DebugControl.write(msg:str, *exc:BaseException | None=None) -> None
Write a line of debug output.
classcoverage.debug.DebugOutputFile
A file-like object that includes pid and cwd information.
methodcoverage.debug.DebugOutputFile.flush() -> None
Flush our file.
methodcoverage.debug.DebugOutputFile.get_one(fileobj:IO[str] | None=None, file_name:str | None=None, filters:Iterable[Callable[[str], str]]=(), interim:bool=False) -> DebugOutputFile
Get a DebugOutputFile.
methodcoverage.debug.DebugOutputFile.write(text:str) -> None
Just like file.write, but filter through all our filters.
classcoverage.debug.DevNullDebug
A DebugControl that won't write anywhere.
classcoverage.debug.NoDebugging
A replacement for DebugControl that will never try to do anything.
methodcoverage.debug.NoDebugging.should(option:str) -> bool
Should we write debug messages?
methodcoverage.debug.NoDebugging.without_callers() -> Iterator[None]
A dummy context manager to satisfy the api.
methodcoverage.debug.NoDebugging.write(msg:str, *exc:BaseException | None=None) -> None
This will never be called.
classcoverage.debug.ProcessTracker
Track process creation for debug logging.
methodcoverage.debug.ProcessTracker.filter(text:str) -> str
Add a message about how new processes came to be.
classcoverage.debug.PytestTracker
Track the current pytest test name to add to debug messages.
methodcoverage.debug.PytestTracker.filter(text:str) -> str
Add a message when the pytest test changes.
funccoverage.debug.add_pid_and_tid(text:str) -> str
A filter to add pid and tid to debug messages.
funccoverage.debug.auto_repr(self:Any) -> str
A function implementing an automatic __repr__ for debugging.
funccoverage.debug.break_in_debugger(func:AnyCallable) -> AnyCallable
A function decorator to stop in the debugger for each call.
funccoverage.debug.clipped_repr(text:str, numchars:int=50) -> str
`repr(text)`, but limited to `numchars`.
funccoverage.debug.decorate_methods(decorator:Callable[..., Any], butnot:Iterable[str]=(), private:bool=False) -> Callable[..., Any]
A class decorator to apply a decorator to methods.
funccoverage.debug.dump_stack_frames(out:TWritable, skip:int=0) -> None
Print a summary of the stack to `out`.
funccoverage.debug.file_summary(filename:str) -> str
A one-line summary of a file, for log messages.
funccoverage.debug.filter_text(text:str, filters:Iterable[Callable[[str], str]]) -> str
Run `text` through a series of filters.
funccoverage.debug.info_formatter(info:Iterable[tuple[str, Any]]) -> Iterable[str]
Produce a sequence of formatted lines from info.
funccoverage.debug.info_header(label:str) -> str
Make a nice header string.
funccoverage.debug.log(msg:str, stack:bool=False) -> None
Write a log message as forcefully as possible.
funccoverage.debug.pp(v:Any) -> None
Debug helper to pretty-print data, including SimpleNamespace objects.
funccoverage.debug.ppformat(v:Any) -> str
Debug helper to pretty-print data, including SimpleNamespace objects.
funccoverage.debug.relevant_environment_display(env:Mapping[str, str]) -> list[tuple[str, str]]
Filter environment variables for a debug display.
funccoverage.debug.short_id(id64:int) -> int
Given a 64-bit id, make a shorter 16-bit one.
funccoverage.debug.short_stack(skip:int=0, full:bool=False, frame_ids:bool=False, short_filenames:bool=False) -> str
Return a string summarizing the call stack.
funccoverage.debug.simplify(v:Any) -> Any
Turn things which are nearly dict/list/etc into dict/list/etc.
funccoverage.debug.write_formatted_info(write:Callable[[str], None], header:str, info:Iterable[tuple[str, Any]]) -> None
Write a sequence of (label,data) pairs nicely.
classcoverage.disposition.FileDisposition
A simple value type for recording what to do with a file.
funccoverage.disposition.disposition_debug_msg(disp:TFileDisposition) -> str
Make a nice debug message of what the FileDisposition is doing.
funccoverage.disposition.disposition_init(cls:type[TFileDisposition], original_filename:str) -> TFileDisposition
Construct and initialize a new FileDisposition object.
classcoverage.env.PYBEHAVIOR
Flags indicating this Python's behavior.
classcoverage.exceptions.ConfigError
A problem with a config file, or a value in one.
classcoverage.exceptions.CoverageException
The base class of all exceptions raised by Coverage.py.
classcoverage.exceptions.CoverageWarning
A warning from Coverage.py.
classcoverage.exceptions.DataError
An error in using a data file.
classcoverage.exceptions.NoCode
We couldn't find any code at all.
classcoverage.exceptions.NoDataError
We didn't have data to work with.
classcoverage.exceptions.NoSource
We couldn't find the source for a module.
classcoverage.exceptions.NotPython
A source file turned out not to be parsable Python.
classcoverage.exceptions.PluginError
A plugin misbehaved.
classcoverage.execfile.PyRunner
Multi-stage execution of Python code.
methodcoverage.execfile.PyRunner.prepare() -> None
Set sys.path properly.
methodcoverage.execfile.PyRunner.run() -> None
Run the Python code!
funccoverage.execfile.find_module(modulename:str) -> tuple[str | None, str, ModuleSpec]
Find the module named `modulename`.
funccoverage.execfile.make_code_from_py(filename:str) -> CodeType
Get source from `filename` and make a code object of it.
funccoverage.execfile.make_code_from_pyc(filename:str) -> CodeType
Get a code object from a .pyc file.
funccoverage.execfile.run_python_module(args:list[str]) -> None
Run a Python module, as though with ``python -m name args...``.
classcoverage.files.GlobMatcher
A matcher for files by file name pattern.
methodcoverage.files.GlobMatcher.match(fpath:str) -> bool
Does `fpath` match one of our file name patterns?
classcoverage.files.Matcher
Common behavior for matchers.
methodcoverage.files.Matcher.info() -> list[str]
A list of strings for displaying when dumping state.
methodcoverage.files.Matcher.match(s:str) -> bool
Does this string match?
classcoverage.files.ModuleMatcher
A matcher for modules in a tree.
methodcoverage.files.ModuleMatcher.match(module_name:str) -> bool
Does `module_name` indicate a module in one of our packages?
classcoverage.files.PathAliases
A collection of aliases for paths.
methodcoverage.files.PathAliases.add(pattern:str, result:str) -> None
Add the `pattern`/`result` pair to the list of aliases.
methodcoverage.files.PathAliases.map(path:str, exists:Callable[[str], bool]=source_exists) -> str
Map `path` through the aliases.
methodcoverage.files.PathAliases.pprint() -> None
Dump the important parts of the PathAliases, for debugging.
classcoverage.files.TreeMatcher
A matcher for files in a tree.
methodcoverage.files.TreeMatcher.match(fpath:str) -> bool
Does `fpath` indicate a file in one of our trees?
funccoverage.files.abs_file(path:str) -> str
Return the absolute normalized form of `path`.
funccoverage.files.actual_path(path:str) -> str
Get the actual path of `path`, including the correct case.
funccoverage.files.canonical_filename(filename:str) -> str
Return a canonical file name for `filename`.
funccoverage.files.flat_rootname(filename:str) -> str
A base for a flat file name to correspond to this file.
funccoverage.files.isabs_anywhere(filename:str) -> bool
Is `filename` an absolute path on any OS?
funccoverage.files.prep_patterns(patterns:Iterable[str]) -> list[str]
Prepare the file patterns for use in a `GlobMatcher`.
funccoverage.files.python_reported_file(filename:str) -> str
Return the string as Python would describe this file name.
funccoverage.files.relative_filename(filename:str) -> str
Return the relative form of `filename`.
funccoverage.files.sep(s:str) -> str
Find the path separator used in this string, or os.sep if none.
funccoverage.files.source_exists(path:str) -> bool
Determine if a source file path exists.
funccoverage.files.zip_location(filename:str) -> tuple[str, str] | None
Split a filename into a zipfile / inner name pair.
classcoverage.html.FileData
The data for each source file of HTML output.
classcoverage.html.FileToReport
A file we're considering reporting.
classcoverage.html.HtmlDataGeneration
Generate structured data to be turned into HTML reports.
methodcoverage.html.HtmlDataGeneration.data_for_file(fr:FileReporter, analysis:Analysis) -> FileData
Produce the data needed for one file's report.
classcoverage.html.HtmlReporter
HTML reporting.
methodcoverage.html.HtmlReporter.copy_static_file(src:str, slug:str='') -> None
Copy a static file into the output directory with cache busting.
methodcoverage.html.HtmlReporter.make_directory() -> None
Make sure our htmlcov directory exists.
methodcoverage.html.HtmlReporter.new_index_page(noun:str, plural_noun:str) -> IndexPage
Create an IndexPage for a kind of region.
methodcoverage.html.HtmlReporter.report(morfs:TMorfs) -> float
Generate an HTML report for `morfs`.
methodcoverage.html.HtmlReporter.should_report(analysis:Analysis, index_page:IndexPage) -> bool
Determine if we'll report this file or region.
methodcoverage.html.HtmlReporter.write_file_index_page(first_html:str, final_html:str) -> None
Write the file index page for this report.
methodcoverage.html.HtmlReporter.write_html_page(ftr:FileToReport) -> None
Generate an HTML page for one source file.
methodcoverage.html.HtmlReporter.write_index_page(index_page:IndexPage, **kwargs:str) -> str
Write an index page specified by `index_page`.
methodcoverage.html.HtmlReporter.write_region_index_pages(files_to_report:Iterable[FileToReport]) -> None
Write the other index pages for this report.
classcoverage.html.IncrementalChecker
Logic and data to support incremental reporting.
methodcoverage.html.IncrementalChecker.can_skip_file(data:CoverageData, fr:FileReporter, rootname:str) -> bool
Can we skip reporting this file?
methodcoverage.html.IncrementalChecker.check_global_data(*data:Any) -> None
Check the global data that can affect incremental reporting.
methodcoverage.html.IncrementalChecker.index_info(fname:str) -> IndexItem
Get the information for index.html for `fname`.
methodcoverage.html.IncrementalChecker.read() -> None
Read the information we stored last time.
methodcoverage.html.IncrementalChecker.set_index_info(fname:str, info:IndexItem) -> None
Set the information for index.html for `fname`.
methodcoverage.html.IncrementalChecker.write() -> None
Write the current status.
classcoverage.html.IndexItem
Information for each index entry, to render an index page.
classcoverage.html.IndexPage
Data for each index page.
classcoverage.html.LineData
The data for each source line of HTML output.
funccoverage.html.copy_with_cache_bust(src:str, dest_dir:str) -> str
Copy `src` to `dest_dir`, adding a hash to the name.
funccoverage.html.data_filename(fname:str) -> str
Return the path to an "htmlfiles" data file of ours.
funccoverage.html.encode_int(n:int) -> str
Create a short HTML-safe string from an integer, using HTML_SAFE.
funccoverage.html.pair(ratio:tuple[int, int]) -> str
Format a pair of numbers so JavaScript can read them in an attribute.
funccoverage.html.pretty_file(filename:str) -> str
Return a prettier version of `filename` for display.
funccoverage.html.read_data(fname:str) -> str
Return the contents of a data file of ours.
funccoverage.html.write_html(fname:str, html:str) -> None
Write `html` to `fname`, properly encoded.
classcoverage.inorout.DirectoryDetail
Details about a directory.
classcoverage.inorout.InOrOut
Machinery for determining what files to measure.
methodcoverage.inorout.InOrOut.check_include_omit_etc(filename:str, frame:FrameType | None) -> str | None
Check a file name against the include, omit, etc, rules.
funccoverage.inorout.InOrOut.nope(disp:TFileDisposition, reason:str) -> TFileDisposition
Simple helper to make it easy to return NO.
methodcoverage.inorout.InOrOut.set_matchers_depending_on_syspath() -> None
Set up matchers that depend on sys.path.
methodcoverage.inorout.InOrOut.sys_info() -> Iterable[tuple[str, Any]]
Our information for Coverage.sys_info.
methodcoverage.inorout.InOrOut.warn_conflicting_settings() -> None
Warn if there are settings that conflict.
funccoverage.inorout.canonical_path(morf:TMorf, directory:bool=False) -> str
Return the canonical path of the module or file `morf`.
funccoverage.inorout.file_and_path_for_module(modulename:str) -> tuple[str | None, list[str]]
Find the file and search path for `modulename`.
funccoverage.inorout.module_has_file(mod:ModuleType) -> bool
Does the module object `mod` have an existing __file__ ?
funccoverage.inorout.module_is_namespace(mod:ModuleType) -> bool
Is the module object `mod` a PEP420 namespace module?
funccoverage.inorout.name_for_module(filename:str, frame:FrameType | None) -> str | None
Get the name of the module for a filename and frame.
classcoverage.jsonreport.JsonReporter
A reporter for writing JSON coverage results.
methodcoverage.jsonreport.JsonReporter.make_branch_summary(nums:Numbers) -> JsonObj
Create a dict summarizing the branch info in `nums`.
methodcoverage.jsonreport.JsonReporter.make_region_data(coverage_data:CoverageData, narrowed_analysis:Analysis, start_line:int) -> JsonObj
Create the data object for one region of a file.
methodcoverage.jsonreport.JsonReporter.make_summary(nums:Numbers) -> JsonObj
Create a dict summarizing `nums`.
methodcoverage.jsonreport.JsonReporter.report(morfs:TMorfs, outfile:IO[str]) -> float
Generate a json report for `morfs`.
classcoverage.lcovreport.LcovReporter
A reporter for writing LCOV coverage reports.
methodcoverage.lcovreport.LcovReporter.lcov_file(rel_fname:str, fr:FileReporter, analysis:Analysis, outfile:IO[str]) -> None
Produces the lcov data for a single file.
methodcoverage.lcovreport.LcovReporter.report(morfs:TMorfs, outfile:IO[str]) -> float
Renders the full lcov report.
funccoverage.lcovreport.lcov_arcs(fr:FileReporter, analysis:Analysis, lines:list[int], outfile:IO[str]) -> None
Emit branch coverage records for an analyzed file.
funccoverage.lcovreport.lcov_field(text:str) -> str
Make `text` safe to write as a field in a single LCOV record.
funccoverage.lcovreport.lcov_functions(fr:FileReporter, file_analysis:Analysis, outfile:IO[str]) -> None
Emit function coverage records for an analyzed file.
funccoverage.lcovreport.lcov_lines(analysis:Analysis, lines:list[int], source_lines:list[str], outfile:IO[str]) -> None
Emit line coverage records for an analyzed file.
funccoverage.lcovreport.line_hash(line:str) -> str
Produce a hash of a source line for use in the LCOV file.
classcoverage.misc.DefaultValue
A sentinel object to use for unusual default-value needs.
classcoverage.misc.Hasher
Hashes Python data for fingerprinting.
methodcoverage.misc.Hasher.digest() -> bytes
Get the full binary digest of the hash.
methodcoverage.misc.Hasher.hexdigest() -> str
Retrieve a 32-char hex digest of the hash.
methodcoverage.misc.Hasher.update(v:Any) -> None
Add `v` to the hash, recursively if needed.
funccoverage.misc.bool_or_none(b:Any) -> bool | None
Return bool(b), but preserve None.
funccoverage.misc.dollar_replace(match:re.Match[str]) -> str
Called for each $replacement.
funccoverage.misc.ensure_dir(directory:str) -> None
Make sure the directory exists.
funccoverage.misc.ensure_dir_for_file(path:str) -> None
Make sure the directory for the path exists.
funccoverage.misc.file_be_gone(path:str) -> None
Remove a file, and don't get annoyed if it doesn't exist.
funccoverage.misc.format_local_datetime(dt:datetime.datetime) -> str
Return a string with local timezone representing the date.
funccoverage.misc.human_sorted(strings:Iterable[str]) -> list[str]
Sort the given iterable of strings the way that humans expect.
funccoverage.misc.human_sorted_items(items:Iterable[SortableItem], reverse:bool=False) -> list[SortableItem]
Sort (string, ...) items the way humans expect.
funccoverage.misc.import_local_file(modname:str, modfile:str | None=None) -> ModuleType
Import a local file as a module.
funccoverage.misc.import_third_party(modname:str) -> tuple[ModuleType, bool]
Import a third-party module we need, but might not be installed.
funccoverage.misc.isolate_module(mod:ModuleType) -> ModuleType
Copy a module so that we are isolated from aggressive mocking.
funccoverage.misc.join_regex(regexes:Iterable[str]) -> str
Combine a series of regex strings into one that matches any of them.
funccoverage.misc.nice_pair(pair:TArc) -> str
Make a nice string representation of a pair of numbers.
funccoverage.misc.plural(n:int, thing:str='', things:str='') -> str
Pluralize a word.
funccoverage.misc.stdout_link(text:str, url:str) -> str
Format text+url as a clickable link for stdout.
funccoverage.misc.substitute_variables(text:str, variables:Mapping[str, str]) -> str
Substitute ``${VAR}`` variables in `text` with their values.
funccoverage.misc.tryint(s:str) -> str | int
If `s` is a number, return an int, else `s` unchanged.
funccoverage.multiproc.patch_multiprocessing(rcfile:str) -> None
Monkey-patch the multiprocessing module.
classcoverage.numbits.NumbitsUnionAgg
SQLite aggregate function for computing union of numbits.
methodcoverage.numbits.NumbitsUnionAgg.finalize() -> bytes
Return the final aggregated result.
methodcoverage.numbits.NumbitsUnionAgg.step(value:bytes) -> None
Process one value in the aggregation.
funccoverage.numbits.num_in_numbits(num:int, numbits:bytes) -> bool
Does the integer `num` appear in `numbits`?
funccoverage.numbits.numbits_any_intersection(numbits1:bytes, numbits2:bytes) -> bool
Is there any number that appears in both numbits?
funccoverage.numbits.numbits_intersection(numbits1:bytes, numbits2:bytes) -> bytes
Compute the intersection of two numbits.
funccoverage.numbits.numbits_to_nums(numbits:bytes) -> list[int]
Convert a numbits into a list of numbers.
funccoverage.numbits.numbits_union(numbits1:bytes, numbits2:bytes) -> bytes
Compute the union of two numbits.
funccoverage.numbits.nums_to_numbits(nums:Iterable[int]) -> bytes
Convert `nums` into a numbits.
funccoverage.numbits.register_sqlite_functions(connection:sqlite3.Connection) -> None
Define numbits functions in a SQLite connection.
classcoverage.parser.ArcStart
The information needed to start an arc.
methodcoverage.parser.AstArcAnalyzer.line_for_node(node:ast.AST) -> TLineNo
What is the right line number to use for this node?
methodcoverage.parser.AstArcAnalyzer.nearest_blocks() -> Iterable[Block]
Yield the blocks in nearest-to-farthest order.
methodcoverage.parser.AstArcAnalyzer.node_exits(node:ast.AST) -> set[ArcStart]
Find the set of arc starts that exit this node.
methodcoverage.parser.AstArcAnalyzer.process_body(body:Sequence[ast.AST], from_start:ArcStart | None=None, prev_starts:set[ArcStart] | None=None) -> set[ArcStart]
Process the body of a compound statement.
methodcoverage.parser.AstArcAnalyzer.process_break_exits(exits:set[ArcStart]) -> None
Add arcs due to jumps from `exits` being breaks.
methodcoverage.parser.AstArcAnalyzer.process_continue_exits(exits:set[ArcStart]) -> None
Add arcs due to jumps from `exits` being continues.
methodcoverage.parser.AstArcAnalyzer.process_raise_exits(exits:set[ArcStart]) -> None
Add arcs due to jumps from `exits` being raises.
methodcoverage.parser.AstArcAnalyzer.process_return_exits(exits:set[ArcStart]) -> None
Add arcs due to jumps from `exits` being returns.
classcoverage.parser.Block
Blocks need to handle various exiting statements in their own ways.
methodcoverage.parser.Block.process_break_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> bool
Process break exits.
methodcoverage.parser.Block.process_continue_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> bool
Process continue exits.
methodcoverage.parser.Block.process_raise_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> bool
Process raise exits.
methodcoverage.parser.Block.process_return_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> bool
Process return exits.
classcoverage.parser.PythonParser
Parse code to find executable lines, excluded lines, etc.
methodcoverage.parser.PythonParser.arc_description(start:TLineNo, end:TLineNo) -> str
Provide an English description of an arc's effect.
methodcoverage.parser.PythonParser.arcs() -> set[TArc]
Get information about the arcs available in the code.
methodcoverage.parser.PythonParser.exit_counts() -> dict[TLineNo, int]
Get a count of exits from that each line.
methodcoverage.parser.PythonParser.first_line(lineno:TLineNo) -> TLineNo
Return the first line number of the statement including `lineno`.
methodcoverage.parser.PythonParser.fix_with_jumps(arcs:Iterable[TArc]) -> set[TArc]
Adjust arcs to fix jumps leaving `with` statements.
methodcoverage.parser.PythonParser.lines_matching(regex:str) -> set[TLineNo]
Find the lines matching a regex.
methodcoverage.parser.PythonParser.missing_arc_description(start:TLineNo, end:TLineNo) -> str
Provide an English sentence describing a missing arc.
methodcoverage.parser.PythonParser.translate_arcs(arcs:Iterable[TArc]) -> set[TArc]
Implement `FileReporter.translate_arcs`.
methodcoverage.parser.PythonParser.translate_lines(lines:Iterable[TLineNo]) -> set[TLineNo]
Implement `FileReporter.translate_lines`.
classcoverage.parser.TAddArcFn
The type for AstArcAnalyzer.add_arc().
classcoverage.parser.TryBlock
A block on the block stack representing a `try` block.
funccoverage.parser.is_constant_test_expr(node:ast.AST) -> tuple[bool, bool]
Is this a compile-time constant test expression?
funccoverage.parser.multiline_map_from_text(text:str) -> dict[TLineNo, TLineNo]
Compute just the multiline map for `text`, without a full parse.
funccoverage.parser.multiline_map_from_tokens(tokens:Iterable[tokenize.TokenInfo]) -> dict[TLineNo, TLineNo]
Compute the multiline map from a stream of tokens.
funccoverage.parser.walk_statement_nodes(root:ast.AST) -> Iterable[ast.AST]
Yield `root` and its descendant statement-level nodes.
funccoverage.patch.apply_patches(cov:Coverage, config:CoverageConfig, debug:TDebugCtl) -> None
Apply invasive patches requested by `[run] patch=`.
funccoverage.phystokens.generate_tokens(text:str) -> TokenInfos
A helper around `tokenize.generate_tokens`.
funccoverage.phystokens.source_encoding(source:bytes) -> str
Determine the encoding for `source`, according to PEP 263.
funccoverage.phystokens.source_token_lines(source:str) -> TSourceTokenLines
Generate a series of lines, one for each line in `source`.
classcoverage.plugin.CoveragePlugin
Base class for coverage.py plug-ins.
methodcoverage.plugin.CoveragePlugin.configure(config:TConfigurable) -> None
Modify the configuration of coverage.py.
methodcoverage.plugin.CoveragePlugin.dynamic_context(frame:FrameType) -> str | None
Get the dynamically computed context label for `frame`.
methodcoverage.plugin.CoveragePlugin.file_reporter(filename:str) -> FileReporter | str
Get the :class:`FileReporter` class to use for a file.
methodcoverage.plugin.CoveragePlugin.file_tracer(filename:str) -> FileTracer | None
Get a :class:`FileTracer` object for a file.
methodcoverage.plugin.CoveragePlugin.find_executable_files(src_dir:str) -> Iterable[str]
Yield all of the executable files in `src_dir`, recursively.
methodcoverage.plugin.CoveragePlugin.sys_info() -> Iterable[tuple[str, Any]]
Get a list of information useful for debugging.
classcoverage.plugin.FileTracer
Support needed for files during the execution phase.
methodcoverage.plugin.FileTracer.dynamic_source_filename(filename:str, frame:FrameType) -> str | None
Get a dynamically computed source file name.
methodcoverage.plugin.FileTracer.source_filename() -> str
The source file name for this file.
classcoverage.plugin_support.DebugFileReporterWrapper
A debugging `FileReporter`.
classcoverage.plugin_support.DebugFileTracerWrapper
A debugging `FileTracer`.
methodcoverage.plugin_support.LabelledDebug.add_label(label:str) -> LabelledDebug
Add a label to the writer, and return a new `LabelledDebug`.
methodcoverage.plugin_support.LabelledDebug.message_prefix() -> str
The prefix to use on messages, combining the labels.
methodcoverage.plugin_support.LabelledDebug.write(message:str) -> None
Write `message`, but with the labels prepended.
classcoverage.plugin_support.Plugins
The currently loaded collection of coverage.py plugins.
methodcoverage.plugin_support.Plugins.add_configurer(plugin:CoveragePlugin) -> None
Add a configuring plugin.
methodcoverage.plugin_support.Plugins.add_dynamic_context(plugin:CoveragePlugin) -> None
Add a dynamic context plugin.
methodcoverage.plugin_support.Plugins.add_file_tracer(plugin:CoveragePlugin) -> None
Add a file tracer plugin.
methodcoverage.plugin_support.Plugins.add_noop(plugin:CoveragePlugin) -> None
Add a plugin that does nothing.
methodcoverage.plugin_support.Plugins.get(plugin_name:str) -> CoveragePlugin
Return a plugin by name.
methodcoverage.plugin_support.Plugins.load_from_callables(plugin_inits:Iterable[TCoverageInit]) -> None
Load plugins from callables provided.
classcoverage.python.PythonFileReporter
Report support for a Python file.
methodcoverage.python.PythonFileReporter.lines() -> set[TLineNo]
Return the line numbers of statements in the file.
methodcoverage.python.PythonFileReporter.parser() -> PythonParser
Lazily create a :class:`PythonParser`.
methodcoverage.python.PythonFileReporter.should_be_python() -> bool
Does it seem like this file should contain Python?
funccoverage.python.get_python_source(filename:str) -> str
Return the source code, as unicode.
funccoverage.python.get_zip_bytes(filename:str) -> bytes | None
Get data from `filename` if it is a zip file path.
funccoverage.python.read_python_source(filename:str) -> bytes
Read the Python source text from `filename`.
funccoverage.python.source_for_file(filename:str) -> str
Return the source filename for `filename`.
funccoverage.python.source_for_morf(morf:TMorf) -> str
Get the source filename for the module-or-file `morf`.
classcoverage.pytracer.PyTracer
Python implementation of the raw data tracer.
methodcoverage.pytracer.PyTracer.activity() -> bool
Has there been any activity?
methodcoverage.pytracer.PyTracer.get_stats() -> dict[str, int] | None
Return a dictionary of statistics, or None.
methodcoverage.pytracer.PyTracer.log(marker:str, *args:Any) -> None
For hard-core logging of what this tracer is doing.
methodcoverage.pytracer.PyTracer.reset_activity() -> None
Reset the activity() flag.
methodcoverage.pytracer.PyTracer.start() -> TTraceFn
Start this Tracer.
methodcoverage.pytracer.PyTracer.stop() -> None
Stop this Tracer.
classcoverage.regions.Context
The nested named context of a function or class.
classcoverage.regions.RegionFinder
An ast visitor that will find and track regions of code.
methodcoverage.regions.RegionFinder.fq_node_name() -> str
Get the current fully qualified name we're processing.
methodcoverage.regions.RegionFinder.handle_ClassDef(node:ast.ClassDef) -> None
Called for `class`.
methodcoverage.regions.RegionFinder.handle_FunctionDef(node:ast.FunctionDef | ast.AsyncFunctionDef) -> None
Called for `def` or `async def`.
methodcoverage.regions.RegionFinder.handle_node(node:ast.AST) -> None
Recursively handle any node.
methodcoverage.regions.RegionFinder.handle_node_body(node:ast.AST) -> None
Recursively handle the nodes in this node's body, if any.
funccoverage.regions.code_regions(source:str) -> list[CodeRegion]
Find function and class regions in source code.
classcoverage.report.SummaryReporter
A reporter for writing the summary report.
methodcoverage.report.SummaryReporter.report(morfs:TMorfs, outfile:IO[str] | None=None) -> float
Writes a report summarizing coverage statistics per module.
methodcoverage.report.SummaryReporter.report_one_file(fr:FileReporter, analysis:Analysis) -> None
Report on just one file, the callback from report().
methodcoverage.report.SummaryReporter.tabular_report() -> None
Writes tabular report formats.
methodcoverage.report.SummaryReporter.write(line:str) -> None
Write a line to the output, adding a newline.
methodcoverage.report.SummaryReporter.write_items(items:Iterable[str]) -> None
Write a list of strings, joined together.
funccoverage.report.escape_markdown(text:str) -> str
Prefix all characters meaningful in markdown tables with backslashes.
classcoverage.report_core.Reporter
What we expect of reporters.
methodcoverage.report_core.Reporter.report(morfs:TMorfs, outfile:IO[str]) -> float
Generate a report of `morfs`, written to `outfile`.
funccoverage.report_core.get_analysis_to_report(coverage:Coverage, morfs:TMorfs) -> Iterable[tuple[FileReporter, Analysis]]
Get the files to report on.
classcoverage.results.Analysis
The results of analyzing a FileReporter.
methodcoverage.results.Analysis.arcs_missing() -> list[TArc]
Returns a sorted list of the un-executed arcs in the code.
methodcoverage.results.Analysis.branch_stats() -> dict[TLineNo, tuple[int, int]]
Get stats about branches.
methodcoverage.results.Analysis.missing_branch_arcs() -> dict[TLineNo, list[TLineNo]]
Return arcs that weren't executed from branch lines.
methodcoverage.results.Analysis.missing_formatted(branches:bool=False) -> str
The missing line numbers, formatted nicely.
classcoverage.results.AnalysisNarrower
For reducing an `Analysis` to a subset of its lines.
methodcoverage.results.AnalysisNarrower.add_regions(liness:Iterable[set[TLineNo]]) -> None
Pre-process a number of sets of line numbers.
methodcoverage.results.AnalysisNarrower.narrow(lines:set[TLineNo]) -> Analysis
Create a narrowed Analysis.
classcoverage.results.Numbers
The numerical results of measuring coverage.
methodcoverage.results.Numbers.n_executed() -> int
Returns the number of executed statements.
methodcoverage.results.Numbers.n_executed_branches() -> int
Returns the number of executed branches.
methodcoverage.results.Numbers.pc_branches() -> float
Returns the percentage covered for branches.
methodcoverage.results.Numbers.pc_covered() -> float
Returns a single percentage value for coverage.
methodcoverage.results.Numbers.pc_statements() -> float
Returns the percentage covered for statements.
methodcoverage.results.Numbers.ratio_branches() -> tuple[int, int]
Return numerator/denominator for branch coverage.
methodcoverage.results.Numbers.ratio_statements() -> tuple[int, int]
Return numerator/denominator for statement coverage.
funccoverage.results.analysis_from_file_reporter(data:CoverageData, precision:int, file_reporter:FileReporter, filename:str) -> Analysis
Create an Analysis from a FileReporter.
funccoverage.results.display_covered(pc:float, precision:int) -> str
Return a displayable total percentage, as a string.
funccoverage.results.format_lines(statements:Iterable[TLineNo], lines:Iterable[TLineNo], arcs:Iterable[tuple[TLineNo, list[TLineNo]]] | None=None) -> str
Nicely format a list of line numbers.
funccoverage.results.should_fail_under(total:float, fail_under:float, precision:int) -> bool
Determine if a total should fail due to fail-under.
classcoverage.sqldata.CoverageData
Manages collected coverage data, including file storage.
methodcoverage.sqldata.CoverageData.add_arcs(arc_data:Mapping[str, Collection[TArc]]) -> None
Add measured arc data.
methodcoverage.sqldata.CoverageData.add_file_tracers(file_tracers:Mapping[str, str]) -> None
Add per-file plugin information.
methodcoverage.sqldata.CoverageData.add_lines(line_data:Mapping[str, Collection[TLineNo]]) -> None
Add measured line data.
methodcoverage.sqldata.CoverageData.arcs(filename:str) -> list[TArc] | None
Get the list of arcs executed for a file.
methodcoverage.sqldata.CoverageData.base_filename() -> str
The base filename for storing data.
methodcoverage.sqldata.CoverageData.close(force:bool=False) -> None
Really close all the database objects.
methodcoverage.sqldata.CoverageData.contexts_by_lineno(filename:str) -> dict[TLineNo, list[str]]
Get the contexts for each line in a file.
methodcoverage.sqldata.CoverageData.data_filename() -> str
Where is the data stored?
methodcoverage.sqldata.CoverageData.dumps() -> bytes
Serialize the current data to a byte string.
methodcoverage.sqldata.CoverageData.erase(parallel:bool=False) -> None
Erase the data in this object.
methodcoverage.sqldata.CoverageData.file_tracer(filename:str) -> str | None
Get the plugin name of the file tracer for a file.
methodcoverage.sqldata.CoverageData.has_arcs() -> bool
Does the database have arcs (True) or lines (False).
methodcoverage.sqldata.CoverageData.lines(filename:str) -> list[TLineNo] | None
Get the list of lines executed for a source file.
methodcoverage.sqldata.CoverageData.loads(data:bytes) -> None
Deserialize data from :meth:`dumps`.
methodcoverage.sqldata.CoverageData.measured_contexts() -> set[str]
A set of all contexts that have been measured.
methodcoverage.sqldata.CoverageData.measured_files() -> set[str]
A set of all files that have been measured.
methodcoverage.sqldata.CoverageData.purge_files(filenames:Collection[str]) -> None
Purge any existing coverage data for the given `filenames`.
methodcoverage.sqldata.CoverageData.read() -> None
Start using an existing data file.
methodcoverage.sqldata.CoverageData.set_context(context:str | None) -> None
Set the current context for future :meth:`add_lines` etc.
methodcoverage.sqldata.CoverageData.set_query_context(context:str) -> None
Set a context for subsequent querying.
methodcoverage.sqldata.CoverageData.set_query_contexts(contexts:Sequence[str] | None) -> None
Set a number of contexts for subsequent querying.
methodcoverage.sqldata.CoverageData.sys_info() -> list[tuple[str, Any]]
Our information for `Coverage.sys_info`.
methodcoverage.sqldata.CoverageData.touch_file(filename:str, plugin_name:str='') -> None
Ensure that `filename` appears in the data, empty if needed.
methodcoverage.sqldata.CoverageData.write() -> None
Ensure the data is written to the data file.
funccoverage.sqldata.filename_match(filename:str) -> re.Match[str] | None
Return a match object to pick apart the filename.
funccoverage.sqldata.filename_suffix(suffix:str | bool | None) -> str | None
Compute a filename suffix for a data file.

About this data

These signatures were extracted from the public source of coveragepy/coveragepy using Python's ast module. Argument names, default values, type annotations and return types are taken verbatim from the code. Implementation bodies are never stored. See how it works for details.

Back to all 805 libraries