Hi,
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.
#!/usr/bin/python
# 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://
www.python.org']
import gevent
from gevent import monkey
# patches stdlib (including socket and ssl modules) to cooperate with
other greenlets
monkey.patch_all()
import urllib2
def print_head(url):
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]
gevent.joinall(jobs)
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:
https://bitbucket.org/ned/coveragepy/issue/177/strange-coverage-results
Thanks!
Jamie