Skip to content

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

Closed

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

  1. sap6011 commented on Jun 27, 2026

    @sap6011
  2. sergey-miryanov commented on Jun 27, 2026

    @sergey-miryanov
  3. sap6011 commented on Jun 27, 2026

    @sap6011
  4. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Jun 27, 2026
  5. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    on Aug 17, 2026
  6. serhiy-storchaka commented on Aug 17, 2026

    @serhiy-storchaka
    Member

    Originally, saving the report and counts was independent. It was broken in a30eacf (bpo-476866/gh-35437) after merging both in write_results(). This change looks not deliberate to me.

    cc @zooko, @gvanrossum, @smontanaro

  7. added a commit that references this issue on Aug 20, 2026
  8. added
    type-featureA feature request or enhancement
    and removed
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Aug 20, 2026
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