Thanks to visit codestin.com
Credit goes to github.com

Skip to content

trace: --count --no-report --file does not save the counts file #152409

Description

@tonghuaroot

Bug report

python -m trace --count --no-report --file FILE script.py exits
successfully but never writes FILE, so counts cannot be accumulated
across runs.

Both options are documented for exactly this workflow:

  • -f, --file FILE — "File to accumulate counts over several runs"
  • -R, --no-report — "Do not generate the coverage report files. Useful
    if you want to accumulate over several runs."

and Doc/library/trace.rst describes --no-report as useful when you
"intend to make several runs with --count, and then produce a single
set of annotated listings at the end."

However the counts are only persisted at the end of
CoverageResults.write_results(), which main() skips entirely under
--no-report:

if not opts.no_report:
    results.write_results(opts.missing, opts.summary, opts.coverdir)

So --no-report suppresses the report and the --file counts. The file
is never created, and because --file is also read back at startup, every
run warns about the file it was supposed to accumulate into:

$ cat prog.py
for i in range(3):
    pass
$ python -m trace --count --no-report --file counts prog.py
Skipping counts file 'counts': [Errno 2] No such file or directory: 'counts'
$ python -m trace --count --no-report --file counts prog.py
Skipping counts file 'counts': [Errno 2] No such file or directory: 'counts'

counts is never written, so accumulation never happens. The same command
without --no-report does write counts (alongside the .cover report).

Suggested fix

Move the counts-saving step out of write_results() into a small
CoverageResults.save_counts() helper and call it on the --no-report
path as well, so --file is honoured regardless of --no-report.

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions