We ran coverage with gevent and noticed when there's a context switch
in a function, the lower half of the function is reported uncovered
although it is executed later.
For example, running the sample code below with coverage, it will
report the 'print' line is not executed in coverage.
# Copyright (c) 2009 Denis Bilenko. See LICENSE for details.
"""Spawn multiple workers and wait for them to complete"""
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://
from gevent import monkey
# patches stdlib (including socket and ssl modules) to cooperate with
print ('Starting %s' % url)
data = urllib2.urlopen(url).read()
print ('%s: %s bytes: %r' % (url, len(data), data[:50]))
jobs = [gevent.spawn(print_head, url) for url in urls]
Gleaned from the coverage blog, briefly coverage.py works by:
Python provides a trace feature: you register a function with
sys.settrace(), and it is called as code is executed. It is passed an
event argument indicating what happened: "call" for entering a new
scope, "return" for leaving a scope, "line" for a line of code
executed, and "exception" for an exception being raised.
Can someone shed some light on this?
Also reported this issue on coverage at: