Integrating command-line generated python .coverage files with PyDev
Asked Answered
D

2

2

My build environment is configured to compile, run and create coverage file at the command line (using Ned Batchelder coverage.py tool).

I'm using Eclipse with PyDev as my editor, but for practical reasons, it's not possible/convenient for me to convert my whole build environment to Eclipse (and thus generate the coverage data directly from the IDE, as it's designed to do)

PyDev seems to be using the same coverage tool (or something very similar to it) to generate its coverage information, so I'm guessing there should be some way of integrating my external coverage files into Eclipse/PyDev.

Any idea on how to do this?

Doorstep answered 17/11, 2008 at 23:4 Comment(0)
Z
3

I needed exactly something like this some time ago, when PyDev still used an older version of coverage.py than the one accessible from the script creator's page.

What I did was detecting where PyDev was saving his .coverage file. For me it was:

 C:\Users\Admin\workspace\.metadata\.plugins\org.python.pydev.debug\.coverage

Then I manually ran a new version of coverage.py from a separate script and told it to save its .coverage file in the place where PyDev saves its. I cannot remember if there is a command-line argument to coverage.py or if I simply copied the .coverage file with a script, but after that, if you simply open the Code Coverage Results View and click Refresh coverage information!, PyDev will nicely process the data as if it generated the file itself.

Zelazny answered 28/1, 2009 at 22:35 Comment(1)
For me, it worked for a really large (20+ KLOC) project with lots of test suites.Zelazny
E
3

I don't know anything about PyDev's integration of coverage.py (or if it even uses coverage.py), but the .coverage files are pretty simple. They are marhsal'ed dictionaries.

I haven't tested this code, but you can try this to combine two .coverage files into one:

import marshal
c1_dict = marshal.load(open(file_name_1, 'rb'))
c2_dict = marshal.load(open(file_name_2, 'rb'))
c1_dict.update(c2_dict)
marshal.dump(c1_dict, open(file_name_out, 'wb'))
Excommunicate answered 18/11, 2008 at 3:15 Comment(1)
I wish I could set both of you and DzinX's answers as accepted, since your insight into .coverage files was helpful in solving part of my problem. His is a more direct answer of my question, so he'll get the rep, but you'd desserve it too.Doorstep
Z
3

I needed exactly something like this some time ago, when PyDev still used an older version of coverage.py than the one accessible from the script creator's page.

What I did was detecting where PyDev was saving his .coverage file. For me it was:

 C:\Users\Admin\workspace\.metadata\.plugins\org.python.pydev.debug\.coverage

Then I manually ran a new version of coverage.py from a separate script and told it to save its .coverage file in the place where PyDev saves its. I cannot remember if there is a command-line argument to coverage.py or if I simply copied the .coverage file with a script, but after that, if you simply open the Code Coverage Results View and click Refresh coverage information!, PyDev will nicely process the data as if it generated the file itself.

Zelazny answered 28/1, 2009 at 22:35 Comment(1)
For me, it worked for a really large (20+ KLOC) project with lots of test suites.Zelazny

© 2022 - 2024 — McMap. All rights reserved.