Someone asked me recently whether coverage.py works on Jython. I had never tried it before, so I took a look.

Coverage.py works in two steps: first, execute the code and record line numbers executed. Then analyze the code to identify parts that could have been executed but weren't. It turns out Jython provides the tool needed for the first (sys.settrace), but not the tools needed for the second (code.co_consts, and other internal representations of compiled code).

I was able to measure a Jython execution by running "coverage run" under Jython 2.5.1 to do the first step. Then I ran "coverage html" under CPython to complete the second step and get a report.

But I don't know if the line numbers will match up perfectly if the two steps are run under different interpreters. I'm looking for someone with a real Jython code base who'd like to try this technique and tell me what they find. Take the tip of the bitbucket repository, install it into your Jython and CPython installations, and run the two commands under the two different interpreters.

Drop me a line if you try this out, I'd love to be able to support Jython with coverage.py.

tagged: , » 5 reactions

Comments

[gravatar]
Jack Diederich 7:06 PM on 22 May 2010

Thanks Ned, for the followup and for organizing the meetup in the first place. Any word on if the audio turned out OK? Stephan sent around his slides which was nice, but about half the night (and the real good stuff) was war stories from the Q&A.

[gravatar]
Steve Gilham 7:51 AM on 23 May 2010

If the recording pass of coverage.py works when you just have sys.settrace, then it should also be able to handle IronPython as well under exactly the same constraints.

I shall have to give that a try.

[gravatar]
Ned Batchelder 8:11 AM on 23 May 2010

I tried IronPython, and found that it doesn't support setuptools, so I couldn't get coverage.py installed.

[gravatar]
Kurt McKee 11:51 PM on 13 Mar 2011

Ned, I was wondering if you've heard any additional word on Jython or IronPython support. Both projects have had a release in the past 10 days, which has prompted me to install them, and I'd sure like to generate a coverage report for two of my projects that accumulates information from CPython 2.4 through 2.7 as well as the latest Jython and IronPython releases!

I've said it before, but I'll say it again: thanks for your work on coverage. It's a marvelous tool that's really helped me identify problem areas in the software I work on.

[gravatar]
Bhushan 12:40 AM on 13 Aug 2012

Ned, I am trying to get coverage setup on jython 2.5.2. My Service.py references to java.util.Date. It compiles and runs when I use jython interpretor. It fails when I try to run "coverage run"

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.