Hi Ned, wondering if you could describe what behavior the newbrough branch sacrifices for someone who doesn't have a deep understanding of coverage.py and gevent internals, so we can decide if this fix would be appropriate for our project (which uses gevent)?
This monkey patch fixed coverage to work with gevent for me:
defpatch_coverage_for_gevent():fromcoverageimportcollectoras_collector,controlas_controlimportcollectionsas_collectionsimportgeventas_gevent_PyTracer=_collector.PyTracerclassDataStack(object):def__init__(self):self.__data=_collections.defaultdict(list)def__idx(self):returnhash(_gevent.getcurrent())defpop(self):returnself.__data[self.__idx()].pop()defappend(self,value):returnself.__data[self.__idx()].append(value)classPyTracer(_PyTracer):def__init__(self):_PyTracer.__init__(self)self.data_stack=DataStack()_collector.PyTracer=PyTracer# Patch coverage, so it uses timid simple tracer by default after monkey patching_coverage=_control.coverageclasscoverage(_coverage):def__init__(self,*args,**kwargs):kwargs.setdefault('timid',True)super(coverage,self).__init__(*args,**kwargs)__import__('pyjack').replace_all_refs(_coverage,coverage)
The workbench project really needs gevent coverage https://github.com/SuperCowPowers/workbench. The project used to use nosetests and we pulled in https://github.com/newbrough/coverage.git. With that configuration we were getting about 94% coverage. We upgraded to pytest and the latest version complains/won't run with the github version of coverage above. So we switched to using the 'stock' coverage module and now we have a coveralls badge that is RED and kinda embarrassing :)
Would it be possible to contract someone to put in the support for gevent? Elance contract perhaps?
Happy to support this work because we'd really like to have our coverage badge not be red all the time, kinda erodes confidence in an embryonic project like ours.. :)
I also tried Vadim's patch and it didn't work for me either. Vadim said he wasn't surprised as these things go I think it was more a quick patch on a particular version than meant to be anything more long lasting. I ran the test 'test_gevent.py' above.. and after some random tinkering noticed that I would occasionally get a thread KeyError exception thrown at the very end (was playing with gevent monkey patching). I found this thread on SO http://stackoverflow.com/questions/8774958/keyerror-in-module-threading-after-a-successful-py-test-run. I think it might be a good place to start... to be honest it's deeper than my knowledge, so I'll just have to hope the pointer helps. :)
1) Add this as the first line of the script above
2) Also note that newer versions of gevent no longer have the gevent.shutdown() call, so that can just be removed.
Just wanted to say that the workbench project ^appears^ to be getting exactly correct coverage with coveragepy 4.0a0 version (Github).. it's a complicated project (client/server) with tons of gevent calls (using ZeroRPC).. so that is a data point that perhaps the 4.0a0 version of coverage IS working on gevent calls, there's just some weird corner case at the very end of the program... perhaps with this thread KeyError exception getting thrown.
I'm a maintainer of gevent itself, and I wanted to give a big shoutout to everyone who helped get this working. I've recently been able to enable this for gevent (here's the coveralls page) and it will be a big help to ensure gevent's quality moving forward. There are still some rough edges---some of the results aren't quite right---but I think that's more due to gevent's configuration and test system than anything else; overall, the coverage results make sense and look good!