Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple use of combine leads to empty .coverage #629

Closed
nedbat opened this issue Jan 11, 2018 · 4 comments
Closed

Multiple use of combine leads to empty .coverage #629

nedbat opened this issue Jan 11, 2018 · 4 comments
Labels
bug Something isn't working combine

Comments

@nedbat
Copy link
Owner

nedbat commented Jan 11, 2018

Originally reported by Anonymous


The full issue we had is reported here on Github (I am @alalazo, in case you want to drop a message there).

Briefly, our program spawn subprocesses and the code therein is tested with the concurrency=multiprocessing parallel=True option of coverage run. Due to a problem yet to identify, very likely on our side, a few of the .coverage.* files generated are empty.

If we recombine the data we have errors like:

#!console

$ coverage combine
Coverage.py warning: Couldn't read data from '/home/travis/build/spack/spack/.coverage.travis-job-spack-spack-323456025.travisci.net.9618.332776': CoverageException: Doesn't seem to be a coverage.py data file
Coverage.py warning: Couldn't read data from '/home/travis/build/spack/spack/.coverage.travis-job-spack-spack-323456025.travisci.net.9686.644486': CoverageException: Doesn't seem to be a coverage.py data file
Coverage.py warning: Couldn't read data from '/home/travis/build/spack/spack/.coverage.travis-job-spack-spack-323456025.travisci.net.9719.277474': CoverageException: Doesn't seem to be a coverage.py data file

but nonetheless we obtain a .coverage file which is the merge of the other hundreds of well formed files. In the case above the three empty files are left in the directory.

At this point if we re-run:

#!console

$ coverage combine
Coverage.py warning: Couldn't read data from '/home/travis/build/spack/spack/.coverage.travis-job-spack-spack-323456025.travisci.net.9618.332776': CoverageException: Doesn't seem to be a coverage.py data file
Coverage.py warning: Couldn't read data from '/home/travis/build/spack/spack/.coverage.travis-job-spack-spack-323456025.travisci.net.9686.644486': CoverageException: Doesn't seem to be a coverage.py data file
Coverage.py warning: Couldn't read data from '/home/travis/build/spack/spack/.coverage.travis-job-spack-spack-323456025.travisci.net.9719.277474': CoverageException: Doesn't seem to be a coverage.py data file

the .coverage file gets rewritten using only the empty files, and all the data get lost.

If you consider this to be an issue, I can try to look into putting together a PR to fix this (maybe checking upfront in combine if a .coverage file is already in the current directory). What do you think?


@nedbat
Copy link
Owner Author

nedbat commented Jan 11, 2018

Can you provide a simple reproducible case? Even if it's "run coverage with parallel, then create a fake empty data file, then run combine twice" or whatever?

@nedbat
Copy link
Owner Author

nedbat commented Jan 15, 2018

From the GitHub issue: to reproduce:

$ cat > foo.py
print("hi")
$ coverage run foo.py
hi
$ cat .coverage
!coverage.py: This is a private format, don't read it directly!{"lines":{"/private/tmp/foo.py":[1]}}
$ touch .coverage.1
$ coverage combine
Coverage.py warning: Couldn't read data from '/private/tmp/.coverage.1': CoverageException: Doesn't seem to be a coverage.py data file
$ cat .coverage
!coverage.py: This is a private format, don't read it directly!{}

"coverage combine" deletes the .coverage file and makes a new one from the combinable files. If a file can't be read, it is left in place instead of being deleted.

BTW, "coverage combine -a" would append to the .coverage file instead of replacing it.

@nedbat
Copy link
Owner Author

nedbat commented Jan 21, 2018

Fixed in aff7c4ca5085 (bb)

Now if combine can't read any of the files it found, it will raise an error.

@nedbat
Copy link
Owner Author

nedbat commented Feb 3, 2018

This was included in coverage.py v4.5, released today.

@nedbat nedbat closed this as completed Feb 3, 2018
@nedbat nedbat added major bug Something isn't working combine labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working combine
Projects
None yet
Development

No branches or pull requests

1 participant