[TIP] live coverage info during running program
ned at nedbatchelder.com
Sat Jun 11 06:24:20 PDT 2016
You should be able to avoid os.system and use coverer.combine and
coverer.html_report, or at least make a new Coverage object to do it.
BTW: setting the object in the sys module is alarming. I wouldn't use
sys as a global scratchpad like that. You can just use your own module
that you import where you need it to hold a global object like that.
On 6/11/16 6:36 AM, Joel B. Mohler wrote:
> After reading the replies to my mail and the bitbucket ticket, I had a
> few more ideas. I now stop/save/start the Coverage object and the
> key is using the parallel support (aka data_suffix=True) for sake of
> getting cumulative results with a combine. In terms of the gui, the
> pause to stop/start is unnoticeable! I suppose it qualifies as a bit
> hacky, but so far it has given robust & reliable results.
> Here are my two code snips to make this work:
> import coverage
> cov = coverage.Coverage(data_suffix=True)
> sys.coverer = cov
> my_program() # the stuff of interest
> # should do a final combine & coverage generation here
> On an 8 second timer through-out the duration of the GUI I run the
> following method.
> def update_coverage_html(self):
> import os
> import threading
> def background_htmlify():
> # HACKY?! combine & html generation
> os.system("coverage combine")
> os.system("coverage html")
> if hasattr(sys, 'coverer'):
> t = threading.Thread(target=background_htmlify)
> On 06/09/2016 08:28 AM, Ned Batchelder wrote:
>> This is a current limitation of these methods, as reported here:
>> I haven't yet looked into what it would take to allow continued
>> collection after the save().
>> On 6/8/16 1:15 PM, Joel B. Mohler wrote:
>>> Dear Python testers,
>>> I'm trying to get a nice feedback loop for coverage testing both a
>>> Python REST
>>> server and the client side GUI program. I thought I could get
>>> coverage to
>>> produce an html report on some interval -- say every 5-10 seconds.
>>> doesn't seem to be a documented use-case ... or is it?
>>> Following the documentation, I've inserted:
>>> import coverage
>>> cov = coverage.Coverage()
>>> sys.coverer = cov # stash this in a global place
>>> my_program() # bunch of code
>>> Inside my_program (which is really a whole GUI event loop), I've
>>> kicked off a
>>> little chunk periodically to update the html:
>>> # attempt at hacking some result-caching by coverage
>>> sys.coverer._measured = True
>>> On the first time I come to my update-the-html code and I get an
>>> directory that looks correct. On the second and subsequent times,
>>> it looks as
>>> though it rewrites exactly the same html.
>>> Is this possible? Is there other caching I need to defeat? There is
>>> file hash
>>> checking code in the HtmlReport which I do not fully understand.
>>> I understand this might be slow. I was hoping that I could get an
>>> CoverageData object quickly then go htmlify it in the background.
>>> That looks
>>> difficult since the HtmlReport takes a Coverage object not a
>>> testing-in-python mailing list
>>> testing-in-python at lists.idyll.org
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
More information about the testing-in-python