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

save() and html_report() prevent further metric gathering #448

Closed
nedbat opened this issue Nov 19, 2015 · 5 comments
Closed

save() and html_report() prevent further metric gathering #448

nedbat opened this issue Nov 19, 2015 · 5 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Nov 19, 2015

Originally reported by Michael Crouch (Bitbucket: creidieki, GitHub: creidieki)


When you call coverage.save() it seems to prevent anything else from being read in, for example, html reports. For example, the following program shows 2 lines covered (the bodies of f1 and f2):

#!python

import coverage

cov = coverage.Coverage()
cov.start()

def f1():
    print 2

def f2():
    print 3

f1()
#cov.save()
f2()
cov.html_report()

However, if you uncomment the "cov.save()" line, it only shows the body of f1() as covered -- it doesn't record the body of f2().

cov.html_report() has the same problem when it's run between f1() and f2().

I'm not sure if this behavior is intended, but the documentation of save() and html_report() don't mention it.

I encountered this behavior while trying to find a "quick and dirty" solution for finding coverage information for the server side of a client/server application. I added cov.start() to the server initialization and added cov.html_report() to an existing server call, with the plan on just making that call to write out the currently-collected coverage information.


@nedbat
Copy link
Owner Author

nedbat commented Jun 2, 2016

Original comment by Matthew Boehm (Bitbucket: mattboehm, GitHub: mattboehm)


Thanks for reporting this, I agree that this is confusing and needs to be fixed.

Looking at the code, it appears that many of these functions (report, html_report, xml_report, save, combine, annotate) end up calling get_data, which resets the collector. While this side effect is documented in get_data, it's not documented in any of these other functions.

As I see it, there are 3 options:

  1. Update the documentation for all these functions to say that they reset the collector
  2. Add a reset_collector=True parameter to these functions
  3. Update the functions so that they don't reset the collector

My guess is that option 3 would break other code out there, but I'll let others weigh in on this.

@nedbat
Copy link
Owner Author

nedbat commented Dec 16, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


What about implicitly calling close() when html_report() & other similar functions are called ? I have a feeling this is not the right thing to do but I'm not sure. What do you think ?

https://bitbucket.org/ned/coveragepy/pull-requests/106/implicitly-close-on-html_report-etc/diff

@nedbat
Copy link
Owner Author

nedbat commented Dec 18, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


It has something in common with save() prevents harvesting on stop()?

@nedbat
Copy link
Owner Author

nedbat commented Mar 4, 2017

Fixed in 12ea6d45d8b8 (bb)

@nedbat
Copy link
Owner Author

nedbat commented Apr 5, 2017

This is in 4.4b1.

@nedbat nedbat closed this as completed Apr 5, 2017
@nedbat nedbat added major bug Something isn't working 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
Projects
None yet
Development

No branches or pull requests

1 participant