views:

44

answers:

2

I'm trying to use Jython instead of Python for a project (want jdbc driver for a sort of rare database). Everything is working OK so far, but I can't find any good tools for code coverage. Does anyone have a solution to this?

The googling I've done seems to indicate that jython is missing some things that code coverage tools need. http://nedbatchelder.com/blog/201005/coveragepy_on_jython.html

How do others solve this? I suppose something like jpype together with normal python would be a way forward, but I would rather not introduce jpype in my environment just for coverage measurements.

+1  A: 

How do others solve this?

Your question is fundamentally, "how can I get tools for languages that don't have built-in tool support?" The hypermodern solution for programming langauges is to try to build in all the necessary support into the particular langauge implementations (reflection, profiling, metaprogramming, ...). While its a nice idea, the amount of engineering required to do it is huge, and .... it often doesn't happen (witness your issue with Jython).

Another way to solve the problem is to step outside the language (or its implementation) and get meta tool building support from engines that are designed to implement tools across a wide variety of languages. That requires engineering, too, but it can be done in pretty general way so that the meta-tool is widely usable. Such meta tools can then be used to implement the tools you don't have.

Our DMS Software Reengineering Toolkit is such a meta tool, providing program parsing, analysis, and transformation, parameterized by explicit langauge definitions. DMS has support for many languages (C, C++, C#, COBOL, Java, PHP, ...) including Python, and it supports dialects, enabling it to handle variations on the "standard" langauge (I suspect Jython is not exactly Python).

At this link you can find a technical paper on how a meta-tool like DMS can be used to implement test coverage for arbitrary langauges. This idea has been used to implement a family of test coverage tools available from my company. (We're likely to do this for Python at some point in the future).

Ira Baxter
+1  A: 

The blog post you link mentions that you can run "coverage run" under Jython, then "coverage html" under CPython. Did you try this? It should give reasonable results.

Ned Batchelder
I did give it a try, although I would prefer not bring more dependencies than necessary into my project. Unfortunately I had problems with the install and got stuck. That's when I started asking for alternatives. :)
Mattias Nilsson
If you'd like help, drop me a line. coverage.py and CPython are only two dependencies, any other tool would be at least one! :)
Ned Batchelder
I'm accepting this answer, if only because it made me fix my environment problem and make sure coverage.py actually installs so that I could test it. :)
Mattias Nilsson