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
| Kind | Count |
|---|---|
| Classes | 70 |
| Functions | 125 |
| Methods | 205 |
API list
class
coverage.annotate.AnnotateReporterGenerate annotated source files showing line coverage.
method
coverage.annotate.AnnotateReporter.annotate_file(fr:FileReporter, analysis:Analysis) -> NoneAnnotate a single file.
method
coverage.annotate.AnnotateReporter.report(morfs:TMorfs, directory:str | None=None) -> NoneRun the report.
class
coverage.bytecode.ByteParserParse bytecode to understand the structure of code.
method
coverage.bytecode.ByteParser.code_objects() -> Iterable[CodeType]Iterate over all the code objects in `code`.
method
coverage.bytecode.ByteParser.find_statements() -> Iterable[TLineNo]Find the statements in `self.code`.
func
coverage.bytecode.bytes_to_lines(code:CodeType) -> dict[TOffset, TLineNo]Make a dict mapping byte code offsets to line numbers.
func
coverage.bytecode.op_set(*op_names:str) -> set[int]Make a set of opcodes from instruction names.
class
coverage.cmdline.CmdOptionParserParse one of the new-style commands for coverage.py.
class
coverage.cmdline.CoverageOptionParserBase OptionParser for coverage.py.
method
coverage.cmdline.CoverageOptionParser.error(msg:str) -> NoReturnOverride optparse.error so sys.exit doesn't get called.
class
coverage.cmdline.CoverageScriptThe command-line interface to coverage.py.
method
coverage.cmdline.CoverageScript.command_line(argv:list[str]) -> intThe bulk of the command line interface to coverage.py.
method
coverage.cmdline.CoverageScript.do_debug(args:list[str]) -> intImplementation of 'coverage debug'.
method
coverage.cmdline.CoverageScript.do_help(options:optparse.Values, args:list[str], parser:optparse.OptionParser) -> boolDeal with help requests.
method
coverage.cmdline.CoverageScript.do_run(options:optparse.Values, args:list[str]) -> intImplementation of 'coverage run'.
method
coverage.cmdline.CoverageScript.do_signal_save(_signum:int, _frame:types.FrameType | None) -> NoneSignal handler to save coverage report
class
coverage.cmdline.MultiParaHelpFormatterAn optparse formatter that allows multi-paragraph help text.
func
coverage.cmdline.main(argv:list[str] | None=None) -> int | NoneThe main entry point to coverage.py.
func
coverage.cmdline.main_deprecated(argv:list[str] | None=None) -> int | NoneFor entry points we'll be getting rid of.
func
coverage.cmdline.prep_help(text:str) -> strPrepare a multi-line string for help to reformat nicely.
func
coverage.cmdline.show_help(error:str | None=None, topic:str | None=None, parser:optparse.OptionParser | None=None) -> NoneDisplay an error message, or the named topic.
func
coverage.cmdline.unglob_args(args:list[str]) -> list[str]Interpret shell wildcards for platforms that need it.
func
coverage.cmdline.unshell_list(s:str) -> list[str] | NoneTurn a command-line argument into a list.
class
coverage.collector.CollectorCollects trace data.
method
coverage.collector.Collector.cached_mapped_file(filename:str) -> strA locally cached version of file names mapped through file_mapper.
method
coverage.collector.Collector.disable_plugin(disposition:TFileDisposition) -> NoneDisable the plugin mentioned in `disposition`.
method
coverage.collector.Collector.flush_data() -> boolSave the collected data to our associated `CoverageData`.
method
coverage.collector.Collector.lock_data() -> NoneLock self.data_lock, for use by tracers.
method
coverage.collector.Collector.mapped_file_dict(d:Mapping[str, T]) -> dict[str, T]Return a dict like d, but with keys modified by file_mapper.
method
coverage.collector.Collector.pause() -> NonePause tracing, but be prepared to `resume`.
method
coverage.collector.Collector.plugin_was_disabled(plugin:CoveragePlugin) -> NoneRecord that `plugin` was disabled during the run.
method
coverage.collector.Collector.post_fork() -> NoneAfter a fork, tracers might need to adjust.
method
coverage.collector.Collector.reset() -> NoneClear collected data, and prepare to collect more.
method
coverage.collector.Collector.resume() -> NoneResume tracing after a `pause`.
method
coverage.collector.Collector.start() -> NoneStart collecting trace information.
method
coverage.collector.Collector.stop() -> NoneStop collecting trace information.
method
coverage.collector.Collector.switch_context(new_context:str | None) -> NoneSwitch to a new dynamic context.
method
coverage.collector.Collector.tracer_name() -> strReturn the class name of the tracer we're using.
method
coverage.collector.Collector.unlock_data() -> NoneUnlock self.data_lock, for use by tracers.
method
coverage.collector.Collector.use_data(covdata:CoverageData, context:str | None) -> NoneUse `covdata` for recording data.
class
coverage.config.CoverageConfigCoverage.py configuration.
method
coverage.config.CoverageConfig.copy() -> CoverageConfigReturn a copy of the configuration.
method
coverage.config.CoverageConfig.deserialize(config_str:str) -> CoverageConfigTake a string from `serialize`, and make a CoverageConfig.
method
coverage.config.CoverageConfig.from_args(**kwargs:TConfigValueIn) -> NoneRead config values from `kwargs`.
method
coverage.config.CoverageConfig.from_file(filename:str, warn:Callable[[str], None], our_file:bool) -> boolRead configuration from a .rc file.
method
coverage.config.CoverageConfig.get_option(option_name:str) -> TConfigValueOut | NoneGet an option from the configuration.
method
coverage.config.CoverageConfig.get_plugin_options(plugin:str) -> TConfigSectionOutGet a dictionary of options for the plugin named `plugin`.
method
coverage.config.CoverageConfig.post_process() -> NoneMake final adjustments to settings to make them usable.
method
coverage.config.CoverageConfig.set_option(option_name:str, value:TConfigValueIn | TConfigSectionIn) -> NoneSet an option in the configuration.
class
coverage.config.HandyConfigParserOur specialization of ConfigParser.
method
coverage.config.HandyConfigParser.get(section:str, option:str, *args:Any, **kwargs:Any) -> strGet a value, replacing environment variables also.
method
coverage.config.HandyConfigParser.get_section(section:str) -> TConfigSectionOutGet the contents of a section, as a dictionary.
method
coverage.config.HandyConfigParser.getfile(section:str, option:str) -> strFix up a file path setting.
method
coverage.config.HandyConfigParser.getlist(section:str, option:str) -> list[str]Read a list of strings.
method
coverage.config.HandyConfigParser.getregexlist(section:str, option:str) -> list[str]Read a list of full-line regexes.
method
coverage.config.HandyConfigParser.read(filenames:Iterable[str], encoding_unused:str | None=None) -> list[str]Read a file name as UTF-8 configuration data.
method
coverage.config.HandyConfigParser.real_section(section:str) -> str | NoneGet the actual name of a section.
func
coverage.config.abs_path_if_exists(path:str) -> stros.path.abspath, but only if the path exists.
func
coverage.config.config_files_to_try(config_file:bool | str) -> list[tuple[str, bool, bool]]What config files should we try to read?
func
coverage.config.process_file_value(path:str) -> strMake adjustments to a file path to make it usable.
func
coverage.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.
func
coverage.config.read_coverage_config(config_file:bool | str, warn:Callable[[str], None], **kwargs:TConfigValueIn) -> CoverageConfigRead the coverage.py configuration.
func
coverage.context.qualname_from_frame(frame:FrameType) -> str | NoneGet a qualified name for the code running in `frame`.
func
coverage.context.should_start_context(frame:FrameType) -> str | NoneThe combiner for multiple context switchers.
func
coverage.context.should_start_context_test_function(frame:FrameType) -> str | NoneIs this frame calling a test_* function?
class
coverage.control.CoverageProgrammatic access to coverage.py.
method
coverage.control.Coverage.analysis2(morf:TMorf) -> tuple[str, list[TLineNo], list[TLineNo], list[TLineNo], str]Analyze a module.
method
coverage.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) -> NoneAnnotate a list of modules.
method
coverage.control.Coverage.branch_stats(morf:TMorf) -> dict[TLineNo, tuple[int, int]]Get branch statistics about a module.
method
coverage.control.Coverage.clear_exclude(which:str='exclude') -> NoneClear the exclude list.
method
coverage.control.Coverage.current() -> Coverage | NoneGet the latest started `Coverage` instance, if any.
method
coverage.control.Coverage.erase() -> NoneErase previously collected coverage data.
method
coverage.control.Coverage.exclude(regex:str, which:str='exclude') -> NoneExclude source lines from execution consideration.
method
coverage.control.Coverage.get_data() -> CoverageDataGet the collected data.
method
coverage.control.Coverage.get_exclude_list(which:str='exclude') -> list[str]Return a list of excluded regex strings.
method
coverage.control.Coverage.get_option(option_name:str) -> TConfigValueOut | NoneGet an option from the configuration.
method
coverage.control.Coverage.load() -> NoneLoad previously-collected coverage data from the data file.
func
coverage.control.Coverage.plugin_info(plugins:list[Any]) -> list[str]Make an entry for the sys_info from a list of plug-ins.
method
coverage.control.Coverage.save() -> NoneSave the collected coverage data to the data file.
method
coverage.control.Coverage.set_option(option_name:str, value:TConfigValueIn | TConfigSectionIn) -> NoneSet an option in the configuration.
method
coverage.control.Coverage.start() -> NoneStart measuring code coverage.
method
coverage.control.Coverage.stop() -> NoneStop measuring code coverage.
method
coverage.control.Coverage.switch_context(new_context:str) -> NoneSwitch to a new dynamic context.
func
coverage.control.override_config(cov:Coverage, **kwargs:TConfigValueIn) -> Iterator[None]Temporarily tweak the configuration of `cov`.
func
coverage.control.process_startup(*force:bool=False, *slug:str='default') -> Coverage | NoneCall this at Python start-up to perhaps measure coverage.
class
coverage.data.DataFileClassifierTrack what files to combine and which to skip.
method
coverage.data.DataFileClassifier.classify(f:str) -> Literal['combine', 'skip']Determine whether to combine or skip this file.
func
coverage.data.add_data_to_hash(data:CoverageData, filename:str, hasher:Hasher) -> NoneContribute `filename`'s data to the `hasher`.
func
coverage.data.combinable_files(data_file:str, data_paths:Iterable[str] | None=None) -> list[str]Make a list of data files to be combined.
func
coverage.data.debug_data_file(filename:str) -> NoneImplementation of 'coverage debug data'.
func
coverage.data.hash_for_data_file(dbfilename:str) -> strGet the hash of the data in the file.
func
coverage.data.line_counts(data:CoverageData, fullpath:bool=False) -> dict[str, int]Return a dict summarizing the line coverage data.
func
coverage.data.sorted_lines(data:CoverageData, filename:str) -> list[int]Get the sorted lines for a file, for tests.
class
coverage.debug.CwdTrackerA class to add cwd info to debug messages.
method
coverage.debug.CwdTracker.filter(text:str) -> strAdd a cwd message for each new cwd.
class
coverage.debug.DebugControlControl and output for debugging.
method
coverage.debug.DebugControl.should(option:str) -> boolDecide whether to output debug information in category `option`.
method
coverage.debug.DebugControl.write(msg:str, *exc:BaseException | None=None) -> NoneWrite a line of debug output.
class
coverage.debug.DebugOutputFileA file-like object that includes pid and cwd information.
method
coverage.debug.DebugOutputFile.flush() -> NoneFlush our file.
method
coverage.debug.DebugOutputFile.get_one(fileobj:IO[str] | None=None, file_name:str | None=None, filters:Iterable[Callable[[str], str]]=(), interim:bool=False) -> DebugOutputFileGet a DebugOutputFile.
method
coverage.debug.DebugOutputFile.write(text:str) -> NoneJust like file.write, but filter through all our filters.
class
coverage.debug.DevNullDebugA DebugControl that won't write anywhere.
class
coverage.debug.NoDebuggingA replacement for DebugControl that will never try to do anything.
method
coverage.debug.NoDebugging.should(option:str) -> boolShould we write debug messages?
method
coverage.debug.NoDebugging.without_callers() -> Iterator[None]A dummy context manager to satisfy the api.
method
coverage.debug.NoDebugging.write(msg:str, *exc:BaseException | None=None) -> NoneThis will never be called.
class
coverage.debug.ProcessTrackerTrack process creation for debug logging.
method
coverage.debug.ProcessTracker.filter(text:str) -> strAdd a message about how new processes came to be.
class
coverage.debug.PytestTrackerTrack the current pytest test name to add to debug messages.
method
coverage.debug.PytestTracker.filter(text:str) -> strAdd a message when the pytest test changes.
func
coverage.debug.add_pid_and_tid(text:str) -> strA filter to add pid and tid to debug messages.
func
coverage.debug.auto_repr(self:Any) -> strA function implementing an automatic __repr__ for debugging.
func
coverage.debug.break_in_debugger(func:AnyCallable) -> AnyCallableA function decorator to stop in the debugger for each call.
func
coverage.debug.clipped_repr(text:str, numchars:int=50) -> str`repr(text)`, but limited to `numchars`.
func
coverage.debug.decorate_methods(decorator:Callable[..., Any], butnot:Iterable[str]=(), private:bool=False) -> Callable[..., Any]A class decorator to apply a decorator to methods.
func
coverage.debug.dump_stack_frames(out:TWritable, skip:int=0) -> NonePrint a summary of the stack to `out`.
func
coverage.debug.file_summary(filename:str) -> strA one-line summary of a file, for log messages.
func
coverage.debug.filter_text(text:str, filters:Iterable[Callable[[str], str]]) -> strRun `text` through a series of filters.
func
coverage.debug.info_formatter(info:Iterable[tuple[str, Any]]) -> Iterable[str]Produce a sequence of formatted lines from info.
func
coverage.debug.info_header(label:str) -> strMake a nice header string.
func
coverage.debug.log(msg:str, stack:bool=False) -> NoneWrite a log message as forcefully as possible.
func
coverage.debug.pp(v:Any) -> NoneDebug helper to pretty-print data, including SimpleNamespace objects.
func
coverage.debug.ppformat(v:Any) -> strDebug helper to pretty-print data, including SimpleNamespace objects.
func
coverage.debug.relevant_environment_display(env:Mapping[str, str]) -> list[tuple[str, str]]Filter environment variables for a debug display.
func
coverage.debug.short_id(id64:int) -> intGiven a 64-bit id, make a shorter 16-bit one.
func
coverage.debug.short_stack(skip:int=0, full:bool=False, frame_ids:bool=False, short_filenames:bool=False) -> strReturn a string summarizing the call stack.
func
coverage.debug.simplify(v:Any) -> AnyTurn things which are nearly dict/list/etc into dict/list/etc.
func
coverage.debug.write_formatted_info(write:Callable[[str], None], header:str, info:Iterable[tuple[str, Any]]) -> NoneWrite a sequence of (label,data) pairs nicely.
class
coverage.disposition.FileDispositionA simple value type for recording what to do with a file.
func
coverage.disposition.disposition_debug_msg(disp:TFileDisposition) -> strMake a nice debug message of what the FileDisposition is doing.
func
coverage.disposition.disposition_init(cls:type[TFileDisposition], original_filename:str) -> TFileDispositionConstruct and initialize a new FileDisposition object.
class
coverage.env.PYBEHAVIORFlags indicating this Python's behavior.
class
coverage.exceptions.ConfigErrorA problem with a config file, or a value in one.
class
coverage.exceptions.CoverageExceptionThe base class of all exceptions raised by Coverage.py.
class
coverage.exceptions.CoverageWarningA warning from Coverage.py.
class
coverage.exceptions.DataErrorAn error in using a data file.
class
coverage.exceptions.NoCodeWe couldn't find any code at all.
class
coverage.exceptions.NoDataErrorWe didn't have data to work with.
class
coverage.exceptions.NoSourceWe couldn't find the source for a module.
class
coverage.exceptions.NotPythonA source file turned out not to be parsable Python.
class
coverage.exceptions.PluginErrorA plugin misbehaved.
class
coverage.execfile.PyRunnerMulti-stage execution of Python code.
method
coverage.execfile.PyRunner.prepare() -> NoneSet sys.path properly.
method
coverage.execfile.PyRunner.run() -> NoneRun the Python code!
func
coverage.execfile.find_module(modulename:str) -> tuple[str | None, str, ModuleSpec]Find the module named `modulename`.
func
coverage.execfile.make_code_from_py(filename:str) -> CodeTypeGet source from `filename` and make a code object of it.
func
coverage.execfile.make_code_from_pyc(filename:str) -> CodeTypeGet a code object from a .pyc file.
func
coverage.execfile.run_python_module(args:list[str]) -> NoneRun a Python module, as though with ``python -m name args...``.
class
coverage.files.GlobMatcherA matcher for files by file name pattern.
method
coverage.files.GlobMatcher.match(fpath:str) -> boolDoes `fpath` match one of our file name patterns?
class
coverage.files.MatcherCommon behavior for matchers.
method
coverage.files.Matcher.info() -> list[str]A list of strings for displaying when dumping state.
method
coverage.files.Matcher.match(s:str) -> boolDoes this string match?
class
coverage.files.ModuleMatcherA matcher for modules in a tree.
method
coverage.files.ModuleMatcher.match(module_name:str) -> boolDoes `module_name` indicate a module in one of our packages?
class
coverage.files.PathAliasesA collection of aliases for paths.
method
coverage.files.PathAliases.add(pattern:str, result:str) -> NoneAdd the `pattern`/`result` pair to the list of aliases.
method
coverage.files.PathAliases.map(path:str, exists:Callable[[str], bool]=source_exists) -> strMap `path` through the aliases.
method
coverage.files.PathAliases.pprint() -> NoneDump the important parts of the PathAliases, for debugging.
class
coverage.files.TreeMatcherA matcher for files in a tree.
method
coverage.files.TreeMatcher.match(fpath:str) -> boolDoes `fpath` indicate a file in one of our trees?
func
coverage.files.abs_file(path:str) -> strReturn the absolute normalized form of `path`.
func
coverage.files.actual_path(path:str) -> strGet the actual path of `path`, including the correct case.
func
coverage.files.canonical_filename(filename:str) -> strReturn a canonical file name for `filename`.
func
coverage.files.flat_rootname(filename:str) -> strA base for a flat file name to correspond to this file.
func
coverage.files.isabs_anywhere(filename:str) -> boolIs `filename` an absolute path on any OS?
func
coverage.files.prep_patterns(patterns:Iterable[str]) -> list[str]Prepare the file patterns for use in a `GlobMatcher`.
func
coverage.files.python_reported_file(filename:str) -> strReturn the string as Python would describe this file name.
func
coverage.files.relative_filename(filename:str) -> strReturn the relative form of `filename`.
func
coverage.files.sep(s:str) -> strFind the path separator used in this string, or os.sep if none.
func
coverage.files.source_exists(path:str) -> boolDetermine if a source file path exists.
func
coverage.files.zip_location(filename:str) -> tuple[str, str] | NoneSplit a filename into a zipfile / inner name pair.
class
coverage.html.FileDataThe data for each source file of HTML output.
class
coverage.html.FileToReportA file we're considering reporting.
class
coverage.html.HtmlDataGenerationGenerate structured data to be turned into HTML reports.
method
coverage.html.HtmlDataGeneration.data_for_file(fr:FileReporter, analysis:Analysis) -> FileDataProduce the data needed for one file's report.
class
coverage.html.HtmlReporterHTML reporting.
method
coverage.html.HtmlReporter.copy_static_file(src:str, slug:str='') -> NoneCopy a static file into the output directory with cache busting.
method
coverage.html.HtmlReporter.make_directory() -> NoneMake sure our htmlcov directory exists.
method
coverage.html.HtmlReporter.new_index_page(noun:str, plural_noun:str) -> IndexPageCreate an IndexPage for a kind of region.
method
coverage.html.HtmlReporter.report(morfs:TMorfs) -> floatGenerate an HTML report for `morfs`.
method
coverage.html.HtmlReporter.should_report(analysis:Analysis, index_page:IndexPage) -> boolDetermine if we'll report this file or region.
method
coverage.html.HtmlReporter.write_file_index_page(first_html:str, final_html:str) -> NoneWrite the file index page for this report.
method
coverage.html.HtmlReporter.write_html_page(ftr:FileToReport) -> NoneGenerate an HTML page for one source file.
method
coverage.html.HtmlReporter.write_index_page(index_page:IndexPage, **kwargs:str) -> strWrite an index page specified by `index_page`.
method
coverage.html.HtmlReporter.write_region_index_pages(files_to_report:Iterable[FileToReport]) -> NoneWrite the other index pages for this report.
class
coverage.html.IncrementalCheckerLogic and data to support incremental reporting.
method
coverage.html.IncrementalChecker.can_skip_file(data:CoverageData, fr:FileReporter, rootname:str) -> boolCan we skip reporting this file?
method
coverage.html.IncrementalChecker.check_global_data(*data:Any) -> NoneCheck the global data that can affect incremental reporting.
method
coverage.html.IncrementalChecker.index_info(fname:str) -> IndexItemGet the information for index.html for `fname`.
method
coverage.html.IncrementalChecker.read() -> NoneRead the information we stored last time.
method
coverage.html.IncrementalChecker.set_index_info(fname:str, info:IndexItem) -> NoneSet the information for index.html for `fname`.
method
coverage.html.IncrementalChecker.write() -> NoneWrite the current status.
class
coverage.html.IndexItemInformation for each index entry, to render an index page.
class
coverage.html.IndexPageData for each index page.
class
coverage.html.LineDataThe data for each source line of HTML output.
func
coverage.html.copy_with_cache_bust(src:str, dest_dir:str) -> strCopy `src` to `dest_dir`, adding a hash to the name.
func
coverage.html.data_filename(fname:str) -> strReturn the path to an "htmlfiles" data file of ours.
func
coverage.html.encode_int(n:int) -> strCreate a short HTML-safe string from an integer, using HTML_SAFE.
func
coverage.html.pair(ratio:tuple[int, int]) -> strFormat a pair of numbers so JavaScript can read them in an attribute.
func
coverage.html.pretty_file(filename:str) -> strReturn a prettier version of `filename` for display.
func
coverage.html.read_data(fname:str) -> strReturn the contents of a data file of ours.
func
coverage.html.write_html(fname:str, html:str) -> NoneWrite `html` to `fname`, properly encoded.
class
coverage.inorout.DirectoryDetailDetails about a directory.
class
coverage.inorout.InOrOutMachinery for determining what files to measure.
method
coverage.inorout.InOrOut.check_include_omit_etc(filename:str, frame:FrameType | None) -> str | NoneCheck a file name against the include, omit, etc, rules.
func
coverage.inorout.InOrOut.nope(disp:TFileDisposition, reason:str) -> TFileDispositionSimple helper to make it easy to return NO.
method
coverage.inorout.InOrOut.set_matchers_depending_on_syspath() -> NoneSet up matchers that depend on sys.path.
method
coverage.inorout.InOrOut.sys_info() -> Iterable[tuple[str, Any]]Our information for Coverage.sys_info.
method
coverage.inorout.InOrOut.warn_conflicting_settings() -> NoneWarn if there are settings that conflict.
func
coverage.inorout.canonical_path(morf:TMorf, directory:bool=False) -> strReturn the canonical path of the module or file `morf`.
func
coverage.inorout.file_and_path_for_module(modulename:str) -> tuple[str | None, list[str]]Find the file and search path for `modulename`.
func
coverage.inorout.module_has_file(mod:ModuleType) -> boolDoes the module object `mod` have an existing __file__ ?
func
coverage.inorout.module_is_namespace(mod:ModuleType) -> boolIs the module object `mod` a PEP420 namespace module?
func
coverage.inorout.name_for_module(filename:str, frame:FrameType | None) -> str | NoneGet the name of the module for a filename and frame.
class
coverage.jsonreport.JsonReporterA reporter for writing JSON coverage results.
method
coverage.jsonreport.JsonReporter.make_branch_summary(nums:Numbers) -> JsonObjCreate a dict summarizing the branch info in `nums`.
method
coverage.jsonreport.JsonReporter.make_region_data(coverage_data:CoverageData, narrowed_analysis:Analysis, start_line:int) -> JsonObjCreate the data object for one region of a file.
method
coverage.jsonreport.JsonReporter.make_summary(nums:Numbers) -> JsonObjCreate a dict summarizing `nums`.
method
coverage.jsonreport.JsonReporter.report(morfs:TMorfs, outfile:IO[str]) -> floatGenerate a json report for `morfs`.
class
coverage.lcovreport.LcovReporterA reporter for writing LCOV coverage reports.
method
coverage.lcovreport.LcovReporter.lcov_file(rel_fname:str, fr:FileReporter, analysis:Analysis, outfile:IO[str]) -> NoneProduces the lcov data for a single file.
method
coverage.lcovreport.LcovReporter.report(morfs:TMorfs, outfile:IO[str]) -> floatRenders the full lcov report.
func
coverage.lcovreport.lcov_arcs(fr:FileReporter, analysis:Analysis, lines:list[int], outfile:IO[str]) -> NoneEmit branch coverage records for an analyzed file.
func
coverage.lcovreport.lcov_field(text:str) -> strMake `text` safe to write as a field in a single LCOV record.
func
coverage.lcovreport.lcov_functions(fr:FileReporter, file_analysis:Analysis, outfile:IO[str]) -> NoneEmit function coverage records for an analyzed file.
func
coverage.lcovreport.lcov_lines(analysis:Analysis, lines:list[int], source_lines:list[str], outfile:IO[str]) -> NoneEmit line coverage records for an analyzed file.
func
coverage.lcovreport.line_hash(line:str) -> strProduce a hash of a source line for use in the LCOV file.
class
coverage.misc.DefaultValueA sentinel object to use for unusual default-value needs.
class
coverage.misc.HasherHashes Python data for fingerprinting.
method
coverage.misc.Hasher.digest() -> bytesGet the full binary digest of the hash.
method
coverage.misc.Hasher.hexdigest() -> strRetrieve a 32-char hex digest of the hash.
method
coverage.misc.Hasher.update(v:Any) -> NoneAdd `v` to the hash, recursively if needed.
func
coverage.misc.bool_or_none(b:Any) -> bool | NoneReturn bool(b), but preserve None.
func
coverage.misc.dollar_replace(match:re.Match[str]) -> strCalled for each $replacement.
func
coverage.misc.ensure_dir(directory:str) -> NoneMake sure the directory exists.
func
coverage.misc.ensure_dir_for_file(path:str) -> NoneMake sure the directory for the path exists.
func
coverage.misc.file_be_gone(path:str) -> NoneRemove a file, and don't get annoyed if it doesn't exist.
func
coverage.misc.format_local_datetime(dt:datetime.datetime) -> strReturn a string with local timezone representing the date.
func
coverage.misc.human_sorted(strings:Iterable[str]) -> list[str]Sort the given iterable of strings the way that humans expect.
func
coverage.misc.human_sorted_items(items:Iterable[SortableItem], reverse:bool=False) -> list[SortableItem]Sort (string, ...) items the way humans expect.
func
coverage.misc.import_local_file(modname:str, modfile:str | None=None) -> ModuleTypeImport a local file as a module.
func
coverage.misc.import_third_party(modname:str) -> tuple[ModuleType, bool]Import a third-party module we need, but might not be installed.
func
coverage.misc.isolate_module(mod:ModuleType) -> ModuleTypeCopy a module so that we are isolated from aggressive mocking.
func
coverage.misc.join_regex(regexes:Iterable[str]) -> strCombine a series of regex strings into one that matches any of them.
func
coverage.misc.nice_pair(pair:TArc) -> strMake a nice string representation of a pair of numbers.
func
coverage.misc.plural(n:int, thing:str='', things:str='') -> strPluralize a word.
func
coverage.misc.stdout_link(text:str, url:str) -> strFormat text+url as a clickable link for stdout.
func
coverage.misc.substitute_variables(text:str, variables:Mapping[str, str]) -> strSubstitute ``${VAR}`` variables in `text` with their values.
func
coverage.misc.tryint(s:str) -> str | intIf `s` is a number, return an int, else `s` unchanged.
func
coverage.multiproc.patch_multiprocessing(rcfile:str) -> NoneMonkey-patch the multiprocessing module.
class
coverage.numbits.NumbitsUnionAggSQLite aggregate function for computing union of numbits.
method
coverage.numbits.NumbitsUnionAgg.finalize() -> bytesReturn the final aggregated result.
method
coverage.numbits.NumbitsUnionAgg.step(value:bytes) -> NoneProcess one value in the aggregation.
func
coverage.numbits.num_in_numbits(num:int, numbits:bytes) -> boolDoes the integer `num` appear in `numbits`?
func
coverage.numbits.numbits_any_intersection(numbits1:bytes, numbits2:bytes) -> boolIs there any number that appears in both numbits?
func
coverage.numbits.numbits_intersection(numbits1:bytes, numbits2:bytes) -> bytesCompute the intersection of two numbits.
func
coverage.numbits.numbits_to_nums(numbits:bytes) -> list[int]Convert a numbits into a list of numbers.
func
coverage.numbits.numbits_union(numbits1:bytes, numbits2:bytes) -> bytesCompute the union of two numbits.
func
coverage.numbits.nums_to_numbits(nums:Iterable[int]) -> bytesConvert `nums` into a numbits.
func
coverage.numbits.register_sqlite_functions(connection:sqlite3.Connection) -> NoneDefine numbits functions in a SQLite connection.
class
coverage.parser.ArcStartThe information needed to start an arc.
method
coverage.parser.AstArcAnalyzer.line_for_node(node:ast.AST) -> TLineNoWhat is the right line number to use for this node?
method
coverage.parser.AstArcAnalyzer.nearest_blocks() -> Iterable[Block]Yield the blocks in nearest-to-farthest order.
method
coverage.parser.AstArcAnalyzer.node_exits(node:ast.AST) -> set[ArcStart]Find the set of arc starts that exit this node.
method
coverage.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.
method
coverage.parser.AstArcAnalyzer.process_break_exits(exits:set[ArcStart]) -> NoneAdd arcs due to jumps from `exits` being breaks.
method
coverage.parser.AstArcAnalyzer.process_continue_exits(exits:set[ArcStart]) -> NoneAdd arcs due to jumps from `exits` being continues.
method
coverage.parser.AstArcAnalyzer.process_raise_exits(exits:set[ArcStart]) -> NoneAdd arcs due to jumps from `exits` being raises.
method
coverage.parser.AstArcAnalyzer.process_return_exits(exits:set[ArcStart]) -> NoneAdd arcs due to jumps from `exits` being returns.
class
coverage.parser.BlockBlocks need to handle various exiting statements in their own ways.
method
coverage.parser.Block.process_break_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> boolProcess break exits.
method
coverage.parser.Block.process_continue_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> boolProcess continue exits.
method
coverage.parser.Block.process_raise_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> boolProcess raise exits.
method
coverage.parser.Block.process_return_exits(exits:set[ArcStart], add_arc:TAddArcFn) -> boolProcess return exits.
class
coverage.parser.PythonParserParse code to find executable lines, excluded lines, etc.
method
coverage.parser.PythonParser.arc_description(start:TLineNo, end:TLineNo) -> strProvide an English description of an arc's effect.
method
coverage.parser.PythonParser.arcs() -> set[TArc]Get information about the arcs available in the code.
method
coverage.parser.PythonParser.exit_counts() -> dict[TLineNo, int]Get a count of exits from that each line.
method
coverage.parser.PythonParser.first_line(lineno:TLineNo) -> TLineNoReturn the first line number of the statement including `lineno`.
method
coverage.parser.PythonParser.fix_with_jumps(arcs:Iterable[TArc]) -> set[TArc]Adjust arcs to fix jumps leaving `with` statements.
method
coverage.parser.PythonParser.lines_matching(regex:str) -> set[TLineNo]Find the lines matching a regex.
method
coverage.parser.PythonParser.missing_arc_description(start:TLineNo, end:TLineNo) -> strProvide an English sentence describing a missing arc.
method
coverage.parser.PythonParser.translate_arcs(arcs:Iterable[TArc]) -> set[TArc]Implement `FileReporter.translate_arcs`.
method
coverage.parser.PythonParser.translate_lines(lines:Iterable[TLineNo]) -> set[TLineNo]Implement `FileReporter.translate_lines`.
class
coverage.parser.TAddArcFnThe type for AstArcAnalyzer.add_arc().
class
coverage.parser.TryBlockA block on the block stack representing a `try` block.
func
coverage.parser.is_constant_test_expr(node:ast.AST) -> tuple[bool, bool]Is this a compile-time constant test expression?
func
coverage.parser.multiline_map_from_text(text:str) -> dict[TLineNo, TLineNo]Compute just the multiline map for `text`, without a full parse.
func
coverage.parser.multiline_map_from_tokens(tokens:Iterable[tokenize.TokenInfo]) -> dict[TLineNo, TLineNo]Compute the multiline map from a stream of tokens.
func
coverage.parser.walk_statement_nodes(root:ast.AST) -> Iterable[ast.AST]Yield `root` and its descendant statement-level nodes.
func
coverage.patch.apply_patches(cov:Coverage, config:CoverageConfig, debug:TDebugCtl) -> NoneApply invasive patches requested by `[run] patch=`.
func
coverage.phystokens.generate_tokens(text:str) -> TokenInfosA helper around `tokenize.generate_tokens`.
func
coverage.phystokens.source_encoding(source:bytes) -> strDetermine the encoding for `source`, according to PEP 263.
func
coverage.phystokens.source_token_lines(source:str) -> TSourceTokenLinesGenerate a series of lines, one for each line in `source`.
class
coverage.plugin.CoveragePluginBase class for coverage.py plug-ins.
method
coverage.plugin.CoveragePlugin.configure(config:TConfigurable) -> NoneModify the configuration of coverage.py.
method
coverage.plugin.CoveragePlugin.dynamic_context(frame:FrameType) -> str | NoneGet the dynamically computed context label for `frame`.
method
coverage.plugin.CoveragePlugin.file_reporter(filename:str) -> FileReporter | strGet the :class:`FileReporter` class to use for a file.
method
coverage.plugin.CoveragePlugin.file_tracer(filename:str) -> FileTracer | NoneGet a :class:`FileTracer` object for a file.
method
coverage.plugin.CoveragePlugin.find_executable_files(src_dir:str) -> Iterable[str]Yield all of the executable files in `src_dir`, recursively.
method
coverage.plugin.CoveragePlugin.sys_info() -> Iterable[tuple[str, Any]]Get a list of information useful for debugging.
class
coverage.plugin.FileTracerSupport needed for files during the execution phase.
method
coverage.plugin.FileTracer.dynamic_source_filename(filename:str, frame:FrameType) -> str | NoneGet a dynamically computed source file name.
method
coverage.plugin.FileTracer.source_filename() -> strThe source file name for this file.
class
coverage.plugin_support.DebugFileReporterWrapperA debugging `FileReporter`.
class
coverage.plugin_support.DebugFileTracerWrapperA debugging `FileTracer`.
method
coverage.plugin_support.LabelledDebug.add_label(label:str) -> LabelledDebugAdd a label to the writer, and return a new `LabelledDebug`.
method
coverage.plugin_support.LabelledDebug.message_prefix() -> strThe prefix to use on messages, combining the labels.
method
coverage.plugin_support.LabelledDebug.write(message:str) -> NoneWrite `message`, but with the labels prepended.
class
coverage.plugin_support.PluginsThe currently loaded collection of coverage.py plugins.
method
coverage.plugin_support.Plugins.add_configurer(plugin:CoveragePlugin) -> NoneAdd a configuring plugin.
method
coverage.plugin_support.Plugins.add_dynamic_context(plugin:CoveragePlugin) -> NoneAdd a dynamic context plugin.
method
coverage.plugin_support.Plugins.add_file_tracer(plugin:CoveragePlugin) -> NoneAdd a file tracer plugin.
method
coverage.plugin_support.Plugins.add_noop(plugin:CoveragePlugin) -> NoneAdd a plugin that does nothing.
method
coverage.plugin_support.Plugins.get(plugin_name:str) -> CoveragePluginReturn a plugin by name.
method
coverage.plugin_support.Plugins.load_from_callables(plugin_inits:Iterable[TCoverageInit]) -> NoneLoad plugins from callables provided.
class
coverage.python.PythonFileReporterReport support for a Python file.
method
coverage.python.PythonFileReporter.lines() -> set[TLineNo]Return the line numbers of statements in the file.
method
coverage.python.PythonFileReporter.parser() -> PythonParserLazily create a :class:`PythonParser`.
method
coverage.python.PythonFileReporter.should_be_python() -> boolDoes it seem like this file should contain Python?
func
coverage.python.get_python_source(filename:str) -> strReturn the source code, as unicode.
func
coverage.python.get_zip_bytes(filename:str) -> bytes | NoneGet data from `filename` if it is a zip file path.
func
coverage.python.read_python_source(filename:str) -> bytesRead the Python source text from `filename`.
func
coverage.python.source_for_file(filename:str) -> strReturn the source filename for `filename`.
func
coverage.python.source_for_morf(morf:TMorf) -> strGet the source filename for the module-or-file `morf`.
class
coverage.pytracer.PyTracerPython implementation of the raw data tracer.
method
coverage.pytracer.PyTracer.activity() -> boolHas there been any activity?
method
coverage.pytracer.PyTracer.get_stats() -> dict[str, int] | NoneReturn a dictionary of statistics, or None.
method
coverage.pytracer.PyTracer.log(marker:str, *args:Any) -> NoneFor hard-core logging of what this tracer is doing.
method
coverage.pytracer.PyTracer.reset_activity() -> NoneReset the activity() flag.
method
coverage.pytracer.PyTracer.start() -> TTraceFnStart this Tracer.
method
coverage.pytracer.PyTracer.stop() -> NoneStop this Tracer.
class
coverage.regions.ContextThe nested named context of a function or class.
class
coverage.regions.RegionFinderAn ast visitor that will find and track regions of code.
method
coverage.regions.RegionFinder.fq_node_name() -> strGet the current fully qualified name we're processing.
method
coverage.regions.RegionFinder.handle_ClassDef(node:ast.ClassDef) -> NoneCalled for `class`.
method
coverage.regions.RegionFinder.handle_FunctionDef(node:ast.FunctionDef | ast.AsyncFunctionDef) -> NoneCalled for `def` or `async def`.
method
coverage.regions.RegionFinder.handle_node(node:ast.AST) -> NoneRecursively handle any node.
method
coverage.regions.RegionFinder.handle_node_body(node:ast.AST) -> NoneRecursively handle the nodes in this node's body, if any.
func
coverage.regions.code_regions(source:str) -> list[CodeRegion]Find function and class regions in source code.
class
coverage.report.SummaryReporterA reporter for writing the summary report.
method
coverage.report.SummaryReporter.report(morfs:TMorfs, outfile:IO[str] | None=None) -> floatWrites a report summarizing coverage statistics per module.
method
coverage.report.SummaryReporter.report_one_file(fr:FileReporter, analysis:Analysis) -> NoneReport on just one file, the callback from report().
method
coverage.report.SummaryReporter.tabular_report() -> NoneWrites tabular report formats.
method
coverage.report.SummaryReporter.write(line:str) -> NoneWrite a line to the output, adding a newline.
method
coverage.report.SummaryReporter.write_items(items:Iterable[str]) -> NoneWrite a list of strings, joined together.
func
coverage.report.escape_markdown(text:str) -> strPrefix all characters meaningful in markdown tables with backslashes.
class
coverage.report_core.ReporterWhat we expect of reporters.
method
coverage.report_core.Reporter.report(morfs:TMorfs, outfile:IO[str]) -> floatGenerate a report of `morfs`, written to `outfile`.
func
coverage.report_core.get_analysis_to_report(coverage:Coverage, morfs:TMorfs) -> Iterable[tuple[FileReporter, Analysis]]Get the files to report on.
class
coverage.results.AnalysisThe results of analyzing a FileReporter.
method
coverage.results.Analysis.arcs_missing() -> list[TArc]Returns a sorted list of the un-executed arcs in the code.
method
coverage.results.Analysis.branch_stats() -> dict[TLineNo, tuple[int, int]]Get stats about branches.
method
coverage.results.Analysis.missing_branch_arcs() -> dict[TLineNo, list[TLineNo]]Return arcs that weren't executed from branch lines.
method
coverage.results.Analysis.missing_formatted(branches:bool=False) -> strThe missing line numbers, formatted nicely.
class
coverage.results.AnalysisNarrowerFor reducing an `Analysis` to a subset of its lines.
method
coverage.results.AnalysisNarrower.add_regions(liness:Iterable[set[TLineNo]]) -> NonePre-process a number of sets of line numbers.
method
coverage.results.AnalysisNarrower.narrow(lines:set[TLineNo]) -> AnalysisCreate a narrowed Analysis.
class
coverage.results.NumbersThe numerical results of measuring coverage.
method
coverage.results.Numbers.n_executed() -> intReturns the number of executed statements.
method
coverage.results.Numbers.n_executed_branches() -> intReturns the number of executed branches.
method
coverage.results.Numbers.pc_branches() -> floatReturns the percentage covered for branches.
method
coverage.results.Numbers.pc_covered() -> floatReturns a single percentage value for coverage.
method
coverage.results.Numbers.pc_statements() -> floatReturns the percentage covered for statements.
method
coverage.results.Numbers.ratio_branches() -> tuple[int, int]Return numerator/denominator for branch coverage.
method
coverage.results.Numbers.ratio_statements() -> tuple[int, int]Return numerator/denominator for statement coverage.
func
coverage.results.analysis_from_file_reporter(data:CoverageData, precision:int, file_reporter:FileReporter, filename:str) -> AnalysisCreate an Analysis from a FileReporter.
func
coverage.results.display_covered(pc:float, precision:int) -> strReturn a displayable total percentage, as a string.
func
coverage.results.format_lines(statements:Iterable[TLineNo], lines:Iterable[TLineNo], arcs:Iterable[tuple[TLineNo, list[TLineNo]]] | None=None) -> strNicely format a list of line numbers.
func
coverage.results.should_fail_under(total:float, fail_under:float, precision:int) -> boolDetermine if a total should fail due to fail-under.
class
coverage.sqldata.CoverageDataManages collected coverage data, including file storage.
method
coverage.sqldata.CoverageData.add_arcs(arc_data:Mapping[str, Collection[TArc]]) -> NoneAdd measured arc data.
method
coverage.sqldata.CoverageData.add_file_tracers(file_tracers:Mapping[str, str]) -> NoneAdd per-file plugin information.
method
coverage.sqldata.CoverageData.add_lines(line_data:Mapping[str, Collection[TLineNo]]) -> NoneAdd measured line data.
method
coverage.sqldata.CoverageData.arcs(filename:str) -> list[TArc] | NoneGet the list of arcs executed for a file.
method
coverage.sqldata.CoverageData.base_filename() -> strThe base filename for storing data.
method
coverage.sqldata.CoverageData.close(force:bool=False) -> NoneReally close all the database objects.
method
coverage.sqldata.CoverageData.contexts_by_lineno(filename:str) -> dict[TLineNo, list[str]]Get the contexts for each line in a file.
method
coverage.sqldata.CoverageData.data_filename() -> strWhere is the data stored?
method
coverage.sqldata.CoverageData.dumps() -> bytesSerialize the current data to a byte string.
method
coverage.sqldata.CoverageData.erase(parallel:bool=False) -> NoneErase the data in this object.
method
coverage.sqldata.CoverageData.file_tracer(filename:str) -> str | NoneGet the plugin name of the file tracer for a file.
method
coverage.sqldata.CoverageData.has_arcs() -> boolDoes the database have arcs (True) or lines (False).
method
coverage.sqldata.CoverageData.lines(filename:str) -> list[TLineNo] | NoneGet the list of lines executed for a source file.
method
coverage.sqldata.CoverageData.loads(data:bytes) -> NoneDeserialize data from :meth:`dumps`.
method
coverage.sqldata.CoverageData.measured_contexts() -> set[str]A set of all contexts that have been measured.
method
coverage.sqldata.CoverageData.measured_files() -> set[str]A set of all files that have been measured.
method
coverage.sqldata.CoverageData.purge_files(filenames:Collection[str]) -> NonePurge any existing coverage data for the given `filenames`.
method
coverage.sqldata.CoverageData.read() -> NoneStart using an existing data file.
method
coverage.sqldata.CoverageData.set_context(context:str | None) -> NoneSet the current context for future :meth:`add_lines` etc.
method
coverage.sqldata.CoverageData.set_query_context(context:str) -> NoneSet a context for subsequent querying.
method
coverage.sqldata.CoverageData.set_query_contexts(contexts:Sequence[str] | None) -> NoneSet a number of contexts for subsequent querying.
method
coverage.sqldata.CoverageData.sys_info() -> list[tuple[str, Any]]Our information for `Coverage.sys_info`.
method
coverage.sqldata.CoverageData.touch_file(filename:str, plugin_name:str='') -> NoneEnsure that `filename` appears in the data, empty if needed.
method
coverage.sqldata.CoverageData.write() -> NoneEnsure the data is written to the data file.
func
coverage.sqldata.filename_match(filename:str) -> re.Match[str] | NoneReturn a match object to pick apart the filename.
func
coverage.sqldata.filename_suffix(suffix:str | bool | None) -> str | NoneCompute 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.