[TIP] live coverage info during running program

Joel B. Mohler joel at kiwistrawberry.us
Wed Jun 8 10:15:41 PDT 2016

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.  This
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 htmlcov
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 up-to-date
CoverageData object quickly then go htmlify it in the background.  That looks
difficult since the HtmlReport takes a Coverage object not a CoverageData.


More information about the testing-in-python mailing list