[TIP] Cannot run coverage.exe against the jython

Ned Batchelder ned at nedbatchelder.com
Mon Aug 4 08:18:33 PDT 2014


On 8/4/14 10:19 AM, Chris Bannan wrote:
> 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
>

You show the command you're running, but you haven't shown what 
happens.  How doesn't it work?

> 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>
>
>
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140804/ff761e2d/attachment-0001.htm>


More information about the testing-in-python mailing list