ryanluker / vscode-coverage-gutters

Display test coverage generated by lcov and xml - works with many languages
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
MIT License
460 stars 88 forks source link

Preview Coverage Report doesn't work #275

Closed RensDimmendaal closed 3 years ago

RensDimmendaal commented 4 years ago

Bug: When I open the "Preview Coverage Report" I don't see the actual report but I get this template file. The gutter coverage works great though 👍

To Reproduce

pytest --cov=mypackage --cov-report=xml:cov.xml tests/

Expected behaviour I expect to see the actual coverage report

Screenshots image

Desktop (please complete the following information):

ryanluker commented 3 years ago

@RensDimmendaal Thanks for submitting an issue! I wasn't able to reproduce this with the latest version of vscode and the example project 🤔 image

Usually this is an issue with the generated html file, can you confirm that you have the latest coverage py package?

ryanluker commented 3 years ago

Closing due to staleness, happy to reopen!

cdonnellytx commented 3 years ago

I'm seeing this issue as well and haven't been able to correct it. Gutters work fine, the report is the only issue.

Is there anything I can do like turning up logging, etc.? Any other troubleshooting?

ryanluker commented 3 years ago

@cdonnellytx There is a couple things you can try. 1) Try out the example project and see if you can preview that html? (screenshot 1) https://github.com/ryanluker/vscode-coverage-gutters/tree/master/example/node

2) Can you check if there is any logging errors around the webview in the gutters log? (screenshot 2)

3) We have some security work being completed by @Kaytbode that might help with your issue if it is a security bit that is preventing the preview from loading 🤔 . https://github.com/ryanluker/vscode-coverage-gutters/issues/237

Screenshot 2021-01-31 100201

Screenshot 2021-01-31 100101

cdonnellytx commented 3 years ago

The preview works for me in the Node sample project, but not the Python one (at least initially).

A couple of things I found out by hacking some additional logging into the extension:

Fortunately it looks like I can get pytest to generate both HTML and XML with the following in pytest.ini:

[pytest]
# ...
addopts =
    --cov=python/foobar
    --cov-report xml
    --cov-report html:coverage/xyz

The HTML report defaults to ${workspaceRoot}/htmlcov/. By setting it above, I finally get a prompt to choose between the venv and it:

image

Which lets me select the correct report: image

Ideally the search would exclude the venv directory (if there is one) under the workspace. (Or maybe I'm not supposed to put it there -- I'm fairly new to Python and so I don't know if I should be creating the venv outside the workspace tree.) This at least explains everything, though.

cdonnellytx commented 3 years ago

Found the coverage-gutters.ignoredPathGlobs setting and was able to get rid of it searching my venv.

Looks like it excludes venv but not .venv by default. Python venv docs use that as a "common" name for the directory; you might want to add it to the default ignored globs...

ryanluker commented 3 years ago

@cdonnellytx Good find, I will add that to the defaults! You can find that addition here https://github.com/ryanluker/vscode-coverage-gutters/commit/f71d17c62e1095334d6366d8b3b82aa723f8e8b1 .

Regarding the virtual env, and where it should be located, I usually put mine in the root (C:\ or ~/ depending on the OS). Having it in the project isn't wrong either though 🤔 .