Skip to content

coverage ¤

Callable for Coverage.py.

Functions:

  • annotate

    Annotate source files with execution information.

  • combine

    Combine a number of data files.

  • debug

    Display information about the internals of coverage.py.

  • erase

    Erase previously collected coverage data.

  • html

    Create an HTML report.

  • json

    Create a JSON report of coverage results.

  • lcov

    Create an LCOV report of coverage results.

  • report

    Report coverage statistics on modules.

  • run

    Run a Python program and measure code execution.

  • xml

    Create an XML report of coverage results.

annotate ¤

annotate(
    *,
    rcfile: str | None = None,
    directory: str | None = None,
    data_file: str | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    debug_opts: list[str] | None = None
) -> None

Annotate source files with execution information.

Make annotated copies of the given files, marking statements that are executed with > and statements that are missed with !.

Parameters:

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • directory (str | None, default: None ) –

    Write the output files to this directory.

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • ignore_errors (bool | None, default: None ) –

    Ignore errors while reading source files.

  • include (list[str] | None, default: None ) –

    Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • omit (list[str] | None, default: None ) –

    Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@lazy(name="coverage.annotate")
def annotate(
    *,
    rcfile: str | None = None,
    directory: str | None = None,
    data_file: str | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Annotate source files with execution information.

    Make annotated copies of the given files, marking statements that are executed
    with `>` and statements that are missed with `!`.

    Parameters:
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        directory: Write the output files to this directory.
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        ignore_errors: Ignore errors while reading source files.
        include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        omit: 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`].
    """
    cli_args = ["annotate"]

    if directory:
        cli_args.append("--directory")
        cli_args.append(directory)

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if ignore_errors:
        cli_args.append("--ignore-errors")

    if include:
        cli_args.append("--include")
        cli_args.append(",".join(include))

    if omit:
        cli_args.append("--omit")
        cli_args.append(",".join(omit))

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

combine ¤

combine(
    *paths: str,
    rcfile: str | None = None,
    append: bool | None = None,
    data_file: str | None = None,
    keep: bool | None = None,
    quiet: bool | None = None,
    debug_opts: list[str] | None = None
) -> None

Combine a number of data files.

Combine data from multiple coverage files. The combined results are written to a single file representing the union of the data. The positional arguments are data files or directories containing data files. If no paths are provided, data files in the default data file's directory are combined.

Parameters:

  • paths (str, default: () ) –

    Paths to combine.

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • append (bool | None, default: None ) –

    Append coverage data to .coverage, otherwise it starts clean each time.

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • keep (bool | None, default: None ) –

    Keep original coverage files, otherwise they are deleted.

  • quiet (bool | None, default: None ) –

    Don't print messages about what is happening.

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@lazy(name="coverage.combine")
def combine(
    *paths: str,
    rcfile: str | None = None,
    append: bool | None = None,
    data_file: str | None = None,
    keep: bool | None = None,
    quiet: bool | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Combine a number of data files.

    Combine data from multiple coverage files. The combined results are written to
    a single file representing the union of the data. The positional arguments are
    data files or directories containing data files. If no paths are provided,
    data files in the default data file's directory are combined.

    Parameters:
        paths: Paths to combine.
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        append: Append coverage data to .coverage, otherwise it starts clean each time.
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        keep: Keep original coverage files, otherwise they are deleted.
        quiet: Don't print messages about what is happening.
        debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
    """
    cli_args = ["combine", *paths]

    if append:
        cli_args.append("--append")

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if keep:
        cli_args.append("--keep")

    if quiet:
        cli_args.append("--quiet")

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

debug ¤

debug(
    topic: Literal[
        "data", "sys", "config", "premain", "pybehave"
    ],
    *,
    rcfile: str | None = None,
    debug_opts: list[str] | None = None
) -> None

Display information about the internals of coverage.py.

Display information about the internals of coverage.py, for diagnosing problems. Topics are: data to show a summary of the collected data; sys to show installation information; config to show the configuration; premain to show what is calling coverage; pybehave to show internal flags describing Python behavior.

Parameters:

  • topic (Literal['data', 'sys', 'config', 'premain', 'pybehave']) –

    Topic to display.

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
@lazy(name="coverage.debug")
def debug(
    topic: Literal["data", "sys", "config", "premain", "pybehave"],
    *,
    rcfile: str | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Display information about the internals of coverage.py.

    Display information about the internals of coverage.py, for diagnosing
    problems. Topics are: `data` to show a summary of the collected data; `sys` to
    show installation information; `config` to show the configuration; `premain`
    to show what is calling coverage; `pybehave` to show internal flags describing
    Python behavior.

    Parameters:
        topic: Topic to display.
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
    """
    cli_args: list[str] = ["debug", topic]

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

erase ¤

erase(
    *,
    rcfile: str | None = None,
    data_file: str | None = None,
    debug_opts: list[str] | None = None
) -> None

Erase previously collected coverage data.

Parameters:

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
@lazy(name="coverage.erase")
def erase(
    *,
    rcfile: str | None = None,
    data_file: str | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Erase previously collected coverage data.

    Parameters:
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
    """
    cli_args = ["erase"]

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

html ¤

html(
    *,
    rcfile: str | None = None,
    contexts: list[str] | None = None,
    directory: str | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    precision: int | None = None,
    quiet: bool | None = None,
    show_contexts: bool | None = None,
    skip_covered: bool | None = None,
    skip_empty: bool | None = None,
    title: str | None = None,
    debug_opts: list[str] | None = None
) -> None

Create an HTML report.

Create an HTML report of the coverage of the files. Each file gets its own page, with the source decorated to show executed, excluded, and missed lines.

Parameters:

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • contexts (list[str] | None, default: None ) –

    Only display data from lines covered in the given contexts. Accepts Python regexes, which must be quoted.

  • directory (str | None, default: None ) –

    Write the output files to this directory.

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • fail_under (int | None, default: None ) –

    Exit with a status of 2 if the total coverage is less than the given number.

  • ignore_errors (bool | None, default: None ) –

    Ignore errors while reading source files.

  • include (list[str] | None, default: None ) –

    Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • omit (list[str] | None, default: None ) –

    Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • precision (int | None, default: None ) –

    Number of digits after the decimal point to display for reported coverage percentages.

  • quiet (bool | None, default: None ) –

    Don't print messages about what is happening.

  • show_contexts (bool | None, default: None ) –

    Show contexts for covered lines.

  • skip_covered (bool | None, default: None ) –

    Skip files with 100% coverage.

  • skip_empty (bool | None, default: None ) –

    Skip files with no code.

  • title (str | None, default: None ) –

    A text string to use as the title on the HTML.

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
@lazy(name="coverage.html")
def html(
    *,
    rcfile: str | None = None,
    contexts: list[str] | None = None,
    directory: str | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    precision: int | None = None,
    quiet: bool | None = None,
    show_contexts: bool | None = None,
    skip_covered: bool | None = None,
    skip_empty: bool | None = None,
    title: str | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Create an HTML report.

    Create an HTML report of the coverage of the files.  Each file gets its own
    page, with the source decorated to show executed, excluded, and missed lines.

    Parameters:
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        contexts: Only display data from lines covered in the given contexts.
            Accepts Python regexes, which must be quoted.
        directory: Write the output files to this directory.
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        fail_under: Exit with a status of 2 if the total coverage is less than the given number.
        ignore_errors: Ignore errors while reading source files.
        include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        precision: Number of digits after the decimal point to display for reported coverage percentages.
        quiet: Don't print messages about what is happening.
        show_contexts: Show contexts for covered lines.
        skip_covered: Skip files with 100% coverage.
        skip_empty: Skip files with no code.
        title: A text string to use as the title on the HTML.
        debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
    """
    cli_args = ["html"]

    if contexts:
        cli_args.append("--contexts")
        cli_args.append(",".join(contexts))

    if directory:
        cli_args.append("--directory")
        cli_args.append(directory)

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if fail_under is not None:
        cli_args.append("--fail-under")
        cli_args.append(str(fail_under))

    if ignore_errors:
        cli_args.append("--ignore-errors")

    if include:
        cli_args.append("--include")
        cli_args.append(",".join(include))

    if omit:
        cli_args.append("--omit")
        cli_args.append(",".join(omit))

    if precision is not None:
        cli_args.append("--precision")
        cli_args.append(str(precision))

    if quiet:
        cli_args.append("--quiet")

    if show_contexts:
        cli_args.append("--show-contexts")

    if skip_covered is True:
        cli_args.append("--skip-covered")
    elif skip_covered is False:
        cli_args.append("--no-skip-covered")

    if skip_empty:
        cli_args.append("--skip-empty")

    if title:
        cli_args.append("--title")
        cli_args.append(title)

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

json ¤

json(
    *,
    rcfile: str | None = None,
    contexts: list[str] | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    output: str | None = None,
    pretty_print: bool | None = None,
    quiet: bool | None = None,
    show_contexts: bool | None = None,
    debug_opts: list[str] | None = None
) -> None

Create a JSON report of coverage results.

Parameters:

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • contexts (list[str] | None, default: None ) –

    Only display data from lines covered in the given contexts. Accepts Python regexes, which must be quoted.

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • fail_under (int | None, default: None ) –

    Exit with a status of 2 if the total coverage is less than the given number.

  • ignore_errors (bool | None, default: None ) –

    Ignore errors while reading source files.

  • include (list[str] | None, default: None ) –

    Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • omit (list[str] | None, default: None ) –

    Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • output (str | None, default: None ) –

    Write the JSON report to this file. Defaults to coverage.json.

  • pretty_print (bool | None, default: None ) –

    Format the JSON for human readers.

  • quiet (bool | None, default: None ) –

    Don't print messages about what is happening.

  • show_contexts (bool | None, default: None ) –

    Show contexts for covered lines.

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
@lazy(name="coverage.json")
def json(
    *,
    rcfile: str | None = None,
    contexts: list[str] | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    output: str | None = None,
    pretty_print: bool | None = None,
    quiet: bool | None = None,
    show_contexts: bool | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Create a JSON report of coverage results.

    Parameters:
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        contexts: Only display data from lines covered in the given contexts.
            Accepts Python regexes, which must be quoted.
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        fail_under: Exit with a status of 2 if the total coverage is less than the given number.
        ignore_errors: Ignore errors while reading source files.
        include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        output: Write the JSON report to this file. Defaults to `coverage.json`.
        pretty_print: Format the JSON for human readers.
        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`].
    """
    cli_args = ["json"]

    if contexts:
        cli_args.append("--contexts")
        cli_args.append(",".join(contexts))

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if fail_under is not None:
        cli_args.append("--fail-under")
        cli_args.append(str(fail_under))

    if ignore_errors:
        cli_args.append("--ignore-errors")

    if include:
        cli_args.append("--include")
        cli_args.append(",".join(include))

    if omit:
        cli_args.append("--omit")
        cli_args.append(",".join(omit))

    if output:
        cli_args.append("-o")
        cli_args.append(output)

    if pretty_print:
        cli_args.append("--pretty-print")

    if quiet:
        cli_args.append("--quiet")

    if show_contexts:
        cli_args.append("--show-contexts")

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

lcov ¤

lcov(
    *,
    rcfile: str | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    output: str | None = None,
    quiet: bool | None = None,
    debug_opts: list[str] | None = None
) -> None

Create an LCOV report of coverage results.

Parameters:

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • fail_under (int | None, default: None ) –

    Exit with a status of 2 if the total coverage is less than the given number.

  • ignore_errors (bool | None, default: None ) –

    Ignore errors while reading source files.

  • include (list[str] | None, default: None ) –

    Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • omit (list[str] | None, default: None ) –

    Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • output (str | None, default: None ) –

    Write the JSON report to this file. Defaults to coverage.json.

  • quiet (bool | None, default: None ) –

    Don't print messages about what is happening.

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
@lazy(name="coverage.lcov")
def lcov(
    *,
    rcfile: str | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    output: str | None = None,
    quiet: bool | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Create an LCOV report of coverage results.

    Parameters:
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        fail_under: Exit with a status of 2 if the total coverage is less than the given number.
        ignore_errors: Ignore errors while reading source files.
        include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        output: Write the JSON report to this file. Defaults to `coverage.json`.
        quiet: Don't print messages about what is happening.
        debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
    """
    cli_args = ["lcov"]

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if fail_under is not None:
        cli_args.append("--fail-under")
        cli_args.append(str(fail_under))

    if ignore_errors:
        cli_args.append("--ignore-errors")

    if include:
        cli_args.append("--include")
        cli_args.append(",".join(include))

    if omit:
        cli_args.append("--omit")
        cli_args.append(",".join(omit))

    if output:
        cli_args.append("-o")
        cli_args.append(output)

    if quiet:
        cli_args.append("--quiet")

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

report ¤

report(
    *,
    rcfile: str | None = None,
    contexts: list[str] | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    output_format: (
        Literal["text", "markdown", "total"] | None
    ) = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    precision: int | None = None,
    sort: (
        Literal[
            "name",
            "stmts",
            "miss",
            "branch",
            "brpart",
            "cover",
        ]
        | None
    ) = None,
    show_missing: bool | None = None,
    skip_covered: bool | None = None,
    skip_empty: bool | None = None,
    debug_opts: list[str] | None = None
) -> None

Report coverage statistics on modules.

Parameters:

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • contexts (list[str] | None, default: None ) –

    Only display data from lines covered in the given contexts.

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • fail_under (int | None, default: None ) –

    Exit with a status of 2 if the total coverage is less than the given number.

  • output_format (Literal['text', 'markdown', 'total'] | None, default: None ) –

    Output format, either text (default), markdown, or total.

  • ignore_errors (bool | None, default: None ) –

    Ignore errors while reading source files.

  • include (list[str] | None, default: None ) –

    Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • omit (list[str] | None, default: None ) –

    Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • precision (int | None, default: None ) –

    Number of digits after the decimal point to display for reported coverage percentages.

  • sort (Literal['name', 'stmts', 'miss', 'branch', 'brpart', 'cover'] | None, default: None ) –

    Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. Default is name.

  • show_missing (bool | None, default: None ) –

    Show line numbers of statements in each module that weren't executed.

  • skip_covered (bool | None, default: None ) –

    Skip files with 100% coverage.

  • skip_empty (bool | None, default: None ) –

    Skip files with no code.

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
@lazy(name="coverage.report")
def report(
    *,
    rcfile: str | None = None,
    contexts: list[str] | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    output_format: Literal["text", "markdown", "total"] | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    precision: int | None = None,
    sort: Literal["name", "stmts", "miss", "branch", "brpart", "cover"] | None = None,
    show_missing: bool | None = None,
    skip_covered: bool | None = None,
    skip_empty: bool | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Report coverage statistics on modules.

    Parameters:
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        contexts: Only display data from lines covered in the given contexts.
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        fail_under: Exit with a status of 2 if the total coverage is less than the given number.
        output_format: Output format, either text (default), markdown, or total.
        ignore_errors: Ignore errors while reading source files.
        include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        precision: Number of digits after the decimal point to display for reported coverage percentages.
        sort: Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. Default is name.
        show_missing: Show line numbers of statements in each module that weren't executed.
        skip_covered: Skip files with 100% coverage.
        skip_empty: Skip files with no code.
        debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
    """
    cli_args = ["report"]

    if contexts:
        cli_args.append("--contexts")
        cli_args.append(",".join(contexts))

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if fail_under is not None:
        cli_args.append("--fail-under")
        cli_args.append(str(fail_under))

    if output_format:
        cli_args.append("--format")
        cli_args.append(output_format)

    if ignore_errors:
        cli_args.append("--ignore-errors")

    if include:
        cli_args.append("--include")
        cli_args.append(",".join(include))

    if omit:
        cli_args.append("--omit")
        cli_args.append(",".join(omit))

    if precision is not None:
        cli_args.append("--precision")
        cli_args.append(str(precision))

    if sort:
        cli_args.append("--sort")
        cli_args.append(sort)

    if show_missing:
        cli_args.append("--show-missing")

    if skip_covered is True:
        cli_args.append("--skip-covered")
    elif skip_covered is False:
        cli_args.append("--no-skip-covered")

    if skip_empty:
        cli_args.append("--skip-empty")

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

run ¤

run(
    pyfile: str,
    *,
    rcfile: str | None = None,
    append: bool | None = None,
    branch: bool | None = None,
    concurrency: list[str] | None = None,
    context: str | None = None,
    data_file: str | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    module: bool | None = None,
    pylib: bool | None = None,
    parallel_mode: bool | None = None,
    source: list[str] | None = None,
    timid: bool | None = None,
    debug_opts: list[str] | None = None
) -> None

Run a Python program and measure code execution.

Parameters:

  • pyfile (str) –

    Python script or module to run.

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • append (bool | None, default: None ) –

    Append coverage data to .coverage, otherwise it starts clean each time.

  • branch (bool | None, default: None ) –

    Measure branch coverage in addition to statement coverage.

  • concurrency (list[str] | None, default: None ) –

    Properly measure code using a concurrency library. Valid values are: eventlet, gevent, greenlet, multiprocessing, thread, or a comma-list of them.

  • context (str | None, default: None ) –

    The context label to record for this coverage run.

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • include (list[str] | None, default: None ) –

    Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • omit (list[str] | None, default: None ) –

    Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • module (bool | None, default: None ) –

    The given file is an importable Python module, not a script path, to be run as python -m would run it.

  • pylib (bool | None, default: None ) –

    Measure coverage even inside the Python installed library, which isn't done by default.

  • parallel_mode (bool | None, default: None ) –

    Append the machine name, process id and random number to the data file name to simplify collecting data from many processes.

  • source (list[str] | None, default: None ) –

    A list of directories or importable names of code to measure.

  • timid (bool | None, default: None ) –

    Use a simpler but slower trace method. Try this if you get seemingly impossible results!

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
@lazy(name="coverage.run")
def run(
    pyfile: str,
    *,
    rcfile: str | None = None,
    append: bool | None = None,
    branch: bool | None = None,
    concurrency: list[str] | None = None,
    context: str | None = None,
    data_file: str | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    module: bool | None = None,
    pylib: bool | None = None,
    parallel_mode: bool | None = None,
    source: list[str] | None = None,
    timid: bool | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Run a Python program and measure code execution.

    Parameters:
        pyfile: Python script or module to run.
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        append: Append coverage data to .coverage, otherwise it starts clean each time.
        branch: Measure branch coverage in addition to statement coverage.
        concurrency: Properly measure code using a concurrency library. Valid values are:
            eventlet, gevent, greenlet, multiprocessing, thread, or a comma-list of them.
        context: The context label to record for this coverage run.
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        module: The given file is an importable Python module, not a script path, to be run as `python -m` would run it.
        pylib: Measure coverage even inside the Python installed library, which isn't done by default.
        parallel_mode: Append the machine name, process id and random number to the data file name
            to simplify collecting data from many processes.
        source: A list of directories or importable names of code to measure.
        timid: Use a simpler but slower trace method. Try this if you get seemingly impossible results!
        debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
    """
    cli_args = ["run", pyfile]

    if append:
        cli_args.append("--append")

    if branch:
        cli_args.append("--branch")

    if concurrency:
        cli_args.append("--concurrency")
        cli_args.append(",".join(concurrency))

    if context:
        cli_args.append("--context")
        cli_args.append(context)

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if include:
        cli_args.append("--include")
        cli_args.append(",".join(include))

    if omit:
        cli_args.append("--omit")
        cli_args.append(",".join(omit))

    if module:
        cli_args.append("--module")

    if pylib:
        cli_args.append("--pylib")

    if parallel_mode:
        cli_args.append("--parallel-mode")

    if source:
        cli_args.append("--source")
        cli_args.append(",".join(source))

    if timid:
        cli_args.append("--timid")

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)

xml ¤

xml(
    *,
    rcfile: str | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    output: str | None = None,
    quiet: bool | None = None,
    skip_empty: bool | None = None,
    debug_opts: list[str] | None = None
) -> None

Create an XML report of coverage results.

Parameters:

  • rcfile (str | None, default: None ) –

    Specify configuration file. By default .coveragerc, setup.cfg, tox.ini, and pyproject.toml are tried [env: COVERAGE_RCFILE].

  • data_file (str | None, default: None ) –

    Read coverage data for report generation from this file. Defaults to .coverage [env: COVERAGE_FILE].

  • fail_under (int | None, default: None ) –

    Exit with a status of 2 if the total coverage is less than the given number.

  • ignore_errors (bool | None, default: None ) –

    Ignore errors while reading source files.

  • include (list[str] | None, default: None ) –

    Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • omit (list[str] | None, default: None ) –

    Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.

  • output (str | None, default: None ) –

    Write the JSON report to this file. Defaults to coverage.json.

  • quiet (bool | None, default: None ) –

    Don't print messages about what is happening.

  • skip_empty (bool | None, default: None ) –

    Skip files with no code.

  • debug_opts (list[str] | None, default: None ) –

    Debug options, separated by commas [env: COVERAGE_DEBUG].

Source code in src/duty/callables/coverage.py
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
@lazy(name="coverage.xml")
def xml(
    *,
    rcfile: str | None = None,
    data_file: str | None = None,
    fail_under: int | None = None,
    ignore_errors: bool | None = None,
    include: list[str] | None = None,
    omit: list[str] | None = None,
    output: str | None = None,
    quiet: bool | None = None,
    skip_empty: bool | None = None,
    debug_opts: list[str] | None = None,
) -> None:
    """Create an XML report of coverage results.

    Parameters:
        rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
            and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
        data_file: Read coverage data for report generation from this file.
            Defaults to `.coverage` [env: `COVERAGE_FILE`].
        fail_under: Exit with a status of 2 if the total coverage is less than the given number.
        ignore_errors: Ignore errors while reading source files.
        include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
        output: Write the JSON report to this file. Defaults to `coverage.json`.
        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`].
    """
    cli_args = ["xml"]

    if data_file:
        cli_args.append("--data-file")
        cli_args.append(data_file)

    if fail_under is not None:
        cli_args.append("--fail-under")
        cli_args.append(str(fail_under))

    if ignore_errors:
        cli_args.append("--ignore-errors")

    if include:
        cli_args.append("--include")
        cli_args.append(",".join(include))

    if omit:
        cli_args.append("--omit")
        cli_args.append(",".join(omit))

    if output:
        cli_args.append("-o")
        cli_args.append(output)

    if quiet:
        cli_args.append("--quiet")

    if skip_empty:
        cli_args.append("--skip-empty")

    if debug_opts:
        cli_args.append("--debug")
        cli_args.append(",".join(debug_opts))

    if rcfile:
        cli_args.append("--rcfile")
        cli_args.append(rcfile)

    _run(cli_args)