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.
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:
Update the documentation for all these functions to say that they reset the collector
Add a reset_collector=True parameter to these functions
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.