[TIP] Cannot run coverage.exe against the jython

Chris Bannan cmbannan at yahoo.com
Mon Aug 4 07:19:51 PDT 2014


I am a consultant working on some python testing tools for a Java Application.

I am using Python 2.7, Jython 2.7b2 and Java 7 on Windows 7

Python is the language of choice for test scripting for my customer.  
Some of the tools require calling java classes.   That is easy enough using Jython.   
But, I am struggling how to get code coverage data for the jython/python code.  

My command line for executing the Unit test is

	java -cp \jython2.7b2\jython.jar org.python.util.jython TestClassForName.py

I cannot run coverage.exe against the python/jython below.
The command line I am using is 
coverage run TestClassForName.py

Coverage does work for other python unittests
Thanks in advance



C Bannan



<code>
"""Unit test sample for Jython  
"""
import unittest
from java.lang import Class
from java.lang import ClassNotFoundException

class TestClassForName(unittest.TestCase):

    def test_ShouldFailWithInvalidClassName(self):

        return_value = load_class('java.lang.Spring')

        self.assertEquals(return_value, 'failure')

    def test_ShouldPassWithValidClassName(self):

        return_value = load_class('java.lang.String')

        self.assertEquals(return_value, 'success')

def load_class(class_name):
    try:
        # for non Java folks, this causes 'class_name' to be loaded
        jclass = Class.forName(class_name).newInstance()
        return 'success'
    except ClassNotFoundException as cnf_excp:
        return 'failure'        

if __name__ == '__main__':
    unittest.main()
</code>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140804/07db1829/attachment.html>


More information about the testing-in-python mailing list