Add method purge_contexts to CoverageData#1569
Conversation
There was a problem hiding this comment.
To make the PR even more complete, you could update the doc string for the CoverageData class to mention the new purge_contexts method.
There was a problem hiding this comment.
I'm going to wait for guidance from Ned since I suspect that changing update() to have an option to replace the contexts is the better way to do this. I did find that doing purge_contexts() and then update() was often rather slow due to the redundant queries. I'm attaching the monkey patch we're using in Wing now which disables things we don't use and thus is just for illustrative purposes showing what we're doing now to solve this issue. I can work up another pull request based on this if this seems like the way to go.

This method lets you purge all data for one or more contexts from coverage data, which is useful when updating with newly obtained data for those contexts. I'm using this to entirely replace coverage stats that originated from earlier runs of a particular test or tests, so that the lines reached by the most recent runs are the only ones in the coverage data for those contexts. Otherwise, I found that lines reached by prior runs of those tests might still be marked as reached, even though they no longer are.
This is in context of a fairly complex system that runs (and re-runs) many tests concurrently, collects coverage data from them independently, and then queues those results for merging into a master file, which is then used in various ways.
It seems like 'combine' in general would not remove old lines for a context, but arguably it should before merging in that data. This could possibly be added as an option for that command, but I didn't do it since I ended up calling the API directly and wasn't sure if others would ever need it.