[TIP] Cannot run coverage.exe against the jython

Ned Batchelder ned at nedbatchelder.com
Sat Aug 9 08:52:42 PDT 2014


Chris, thanks for persisting with this.  Most of the problems below have 
to do with getting coverage installed into the Jython installation 
instead wherever it wants to by default.  We can take this discussion to 
the coverage ticket that you wrote, thanks! :)

--Ned.

On 8/6/14 8:21 AM, Chris Bannan wrote:
> I have figured out how to use coverage.py with jython with some 
> work-arounds.
> This is a lengthy explanation.  There were multiple problems
>
> 1.  The jython install instructions did not specify putting jython on 
> the path.
> When I did that I could run jython directly, rather than via Java as I 
> wrote in my first post.
> jython TestClassForName.py
>
> 2.  However, I still could not run coverage using jython.  I got this 
> error
> C:\cygwin64\home\cbannan\python>coverage run TestClassForName.py
> Traceback (most recent call last):
>  File "TestClassForName.py", line 6, in <module>
> from java.lang import Class
> ImportError: No module named java.lang
>
> Java could not be found by coverage
>
> 3.  When I installed coverage, I installed it using the Windows 
> installer -- coverage-3.7.1-cp27-none-win32.whl
> The jython site suggests running python in these ways.
> ./python -m coverage
> ./python COVERAGEDIR run --pylib Lib/test/regrtest.py
>
> While I think these are instructions for getting code coverage of 
> jython itself, they gave me an idea
> I tried ./jython -m coverage, but it failed as follows
> Traceback (most recent call last):
>  File "<string>", line 1, in <module>
>  File "C:\jython2.7b2\Lib\runpy.py", line 170, in run_module
> mod_name, loader, code, fname = _get_module_details(mod_name)
>  File "C:\jython2.7b2\Lib\runpy.py", line 103, in _get_module_details
> raise ImportError("No module named %s" % mod_name)
> ImportError: No module named coverage
>
> My coverage install does not have coveragepy, just the coverage.exe. 
>  So I installed coverage again using hg, as suggested on on they 
> Jython site
> I then hunted for coveragepy and found a directory of that name. 
>  Looking for a python file to run, I guessed an tried __main__.py
> That let me run coverage via jython for everything except the coverage 
> html command as follows
> jython C:\cygwin64\home\cbannan\coveragepy\__main__.py help
> jython C:\cygwin64\home\cbannan\coveragepy\__main__.py erase
> jython C:\cygwin64\home\cbannan\coveragepy\__main__.py run 
> TestClassForName.py
> 4.  I suspect that is not how it is intended to be used, but it works, 
> except, again, for the html option
> That fails, as follows:
> File "C:\cygwin64\home\cbannan\coveragepy\__main__.py", line 8, in 
> <module>
>   run_globals = runpy.run_module(PKG, run_name='__main__', alter_sys=True)
> File "C:\cygwin64\home\cbannan\coveragepy\__main__.py", line 8, in 
> <module>
>   run_globals = runpy.run_module(PKG, run_name='__main__', alter_sys=True)
> File "C:\jython2.7b2\Lib\runpy.py", line 175, in run_module
>   return _run_module_code(code, init_globals, run_name,
> File "C:\jython2.7b2\Lib\runpy.py", line 81, in _run_module_code
>   _run_code(code, mod_globals, init_globals,
> File "C:\jython2.7b2\Lib\runpy.py", line 72, in _run_code
>   exec code in run_globals
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\__main__.py", line 
> 4, in <module>
>   sys.exit(main())
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\cmdline.py", line 
> 747, in main
>   status = CoverageScript().command_line(argv)
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\cmdline.py", line 
> 747, in main
>   status = CoverageScript().command_line(argv)
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\cmdline.py", line 
> 465, in command_line
>   total = self.coverage.html_report(
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\control.py", line 
> 689, in html_report
>   return reporter.report(morfs)
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\html.py", line 109, 
> in report
>   self.report_files(self.html_file, morfs, self.config.html_dir)
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\report.py", line 
> 82, in report_files
>   report_fn(cu, self.coverage._analyze(cu))
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\report.py", line 
> 82, in report_files
>   report_fn(cu, self.coverage._analyze(cu))
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\control.py", line 
> 619, in _analyze
>   return Analysis(self, it)
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\results.py", line 
> 20, in __init__
>   self.statements, self.excluded = self.parser.parse_source()
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\parser.py", line 
> 217, in parse_source
>   self._raw_parse()
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\parser.py", line 
> 217, in parse_source
>   self._raw_parse()
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\parser.py", line 
> 112, in _raw_parse
>   self.excluded = self.lines_matching(self.exclude)
> File "C:\cygwin64\home\cbannan\coveragepy\coverage\parser.py", line 
> 99, in lines_matching
>   for i, ltext in enumerate(self.lines, start=1):
> TypeError: enumerate() takes at most 1 arguments (2 given)
> To generate the coverage html, I reverted to the recommended 
> command:coverage html
>
> I think I have some bugs to log, i.e. for jython doc and for coverage
>
> Thanks for your help.
>
> Chris
> cmbannan at yahoo.com
>
>
>
>
>
>
> _______________________________________________
> 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/20140809/9f98c6dd/attachment-0001.htm>


More information about the testing-in-python mailing list