-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support python coverage #224
Comments
@ergoithz thanks for submitting an issue! do you know what coverage file type |
Example file with line coverage: !coverage.py: This is a private format, don't read it directly!{"lines":{"/absolute/path/to/file.py":[3,4,5,6,7,8,9,10]}} Example file with branch coverage: !coverage.py: This is a private format, don't read it directly!{"arcs":{"/absolute/path/to/file.py":[[-4,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[10,11],[11,-4]] This are to be found on project root with name |
My project kcov, https://github.com/SimonKagstrom/kcov, supports collecting Python code coverage and outputting it in a format which coverage-gutters understands. I use it for C/C++ code, but since the output is the same regardless of language, I don't see why the Python support shouldn't work. Caveat: kcov only runs on OSX/Linux/FreeBSD |
No branch coverage though. |
@ergoithz Looking at the coverage.py [0] it does seem doable to make another parser [1] (similar to the other ones created so far, I am not sure I would be able to get to it before the next major release ( Resources0: https://github.com/nedbat/coveragepy/ |
The python coverage module already has a command to convert the .coverage file to html and cobertura compliant xml which then can be parse with this extension. Here are the commands i run -
I was quite confused getting this to work at first as the extension by default only searches for files named cov.xml whereas the default output filename from the coverage xml command is coverage.xml. If for some reason you can't rename the xml file there is also an option to change the default xml file in the extension settings. @ryanluker might be worth adding coverage.xml as a default somewhere ? |
@drettie Thanks for the input! Good to know there is a workaround for now with regards to the usual python coverage generation flow (still planning on adding support for this in Interesting mention around the default file name 🤔 I vaguely remember setting it to One way to improve this would be to add multiple default coverage file names for the same type of coverage (can already be done via the default settings https://github.com/ryanluker/vscode-coverage-gutters/blob/v2.4.0/package.json#L137-L145). This could be apart of the work set out in this ticket or if someone wishes to quickly add it to the |
it was a matter of minutes to configure pytest to instruct coverage.py to also create an xml file bya adding [pytest]
junit_family=legacy
addopts=-v -sv --cov --cov-report xml:cov.xml --cov-report html
|
@Josverl your comment makes no sense as is about pytest-cov plugin and not coverage.py it. Plugin used the second but the ticket is about coverage.py itself, especially as the plugin use is discouraged. |
I stand corrected on that this is indeed configuring the plugin , |
What I am trying to explain here is that many users of coverage.py already have complex workflows, ones that likely upload the files to remove servers or use integration with third party services that expect specific filenames and locations. Most people will rely on default settings, so vscode-coverage-gutters should do the same and ensure that is able to detect coverage files that use the default layout, without requiring user to do any modification. This is quite important because I really doubt any random repository owner would accept a pull-request that reconfigures the way coverage files are managed just to please one extension of vscode. Likely many of them are not using vscode at all. The real value of this extension comes into place when "it just works"... as long you are following standard patterns. |
but then why this discussion if all one needs is to run the command anyway , just trying to help out , not flame intended , but i'm bailing out of this conversation. good luck ✌🏻 |
@Josverl @ssbarnea Thanks for the spirited discussion, hopefully calmer heads have prevailed in the end. We will continue to support what is laid out in the example python project (using the older setup) that is covered via integrations test to make sure that flow still can be used by python devs. Once the new coverage parser is developed, we will add this as a new option for python devs, while still supporting the older flow in the meantime as well. |
Thanks a lot! That is a great way to deal with this. Doing an ack on the problem and expressing the willingness to address it is just perfect. |
starting from coverage 6.3, lcov file generation is now supported via its new 'lcov' command, no extra dependencies required |
@ergoithz Thanks for the heads-up! I think this ticket can be closed shortly but I will try to get in a small example using coverage 6.3 as an example for folks to use. |
fwiw, pytest-cov doesn't (yet? pytest-dev/pytest-cov#536) support lcov.xml generation, so it may be worth parsing the coverage.py coverage.xml format; primarily b/c calling pytest+pytest-cov from vscode still only generates the coverage.xml |
@MarximusMaximus Thanks for the extra info, looks like there might have been some action on this front pytest-dev/pytest-cov#536 (comment) . That others above could leverage. |
Going to close this issue as there are a few options available now and discussed above. Folks are more than welcome to build the parser discussed near the top of the issue discussion and we can reopen the ticket at that point. |
The python tool
coverage
is much more common and mainstream thanpytest-cov
(which requires non-standardpytest
runner) see both pytest-cov stats and coverage statsThis means this plugin is not useful for projects not willing to use the non-standard
pytest
.Please consider adding support for
coverage
.The text was updated successfully, but these errors were encountered: