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

How do I configure to color coverage on Azure Functions (Python) Project? #373

Closed ecormaksin closed 2 years ago

ecormaksin commented 2 years ago

I try to apply your extension to Azure Functions (Python) Project.

However, vscode editor lines are not colored, and "No Coverage" is displayed.

When I exuecute your project example, the editor lines are colored, and "xx% Coverage" is displayed. So, my local machine seems to be fine.

My project repository is here.

And I upload 2 screenshots. (your project example and my Azure Functions project) your_project_example my_azure_functions_project

I switched to Python interpreter from project's .venv to local machine's global exe, however the problem didn't solve.

How do I configure to color coverage on Azure Functions (Python) Project?

ryanluker commented 2 years ago

@ecormaksin Thanks for the issue! Good idea trying out the examples project that will cut down the amount of triaging I will need to ask you to do. Based on your repo and your screenshots I would say you are missing a coverage file (.lcov).

Take a look at the readme for the python example to get an idea of how to generate a coverage file for your tests. https://github.com/ryanluker/vscode-coverage-gutters/tree/master/example/python#readme

There is also a few previous github issues that mention generating code coverage files from python as well. https://github.com/ryanluker/vscode-coverage-gutters/issues/224#issuecomment-530197803

ecormaksin commented 2 years ago

@ryanluker Thank you for your reply.

Is it needed that the extension of a coverage file must be .lcov?

In your project example, .lcov file is not created, is it? (That is because the command example is py.test foobar --cov-report xml:cov.xml --cov foobar.)

Coverage-gutter extension seems to search {lcov.info,cov.xml,coverage.xml,jacoco.xml,coverage.cobertura.xml}.

In my project, coverage.xml is created. (coverage.xml is listed to .gitignore by default when I created the project using Azure Functions extension.)

I change pytest args from xml to xml:cov.xml, however the result does not change.

ryanluker commented 2 years ago

@ecormaksin You are correct that any of those file names matching will work .lcov is just one example. Where is the coverage.xml file in relation to the project? It will need to be inside the folder you open with vscode for the extension to find the file 🤔.

ryanluker commented 2 years ago

@ecormaksin I ran your example project locally and was able to get the coverage to be picked up by doing the following.

[1653143161420][coverageservice]: LOADING
[1653143161440][coverageservice]: Loading 1 file(s)
[1653143161440][coverageservice]: c:\Users\ryanl\dev\azure_functions_coverage_test\cov.xml
[1653143161440][coverageservice]: Loaded 1 data file(s)
[1653143161441][coverageservice]: Caching 6 coverage(s)
[1653143161441][coverageservice]: READY
[1653143161441][coverageservice]: RENDERING
[1653143161441][renderer][section test name]: module_a.py
[1653143161441][renderer][section file path]: C:\Users\ryanl\dev\azure_functions_coverage_test\shared_code\module_a.py
[1653143161441][coverageservice]: READY
[1653143161441][coverageservice]: Listening to file system at {c:\Users\ryanl\dev\azure_functions_coverage_test}/**/{lcov.info,cov.xml,coverage.xml,jacoco.xml,coverage.cobertura.xml}
(venv) PS C:\Users\ryanl\dev\azure_functions_coverage_test> py.test --cov-report xml:cov.xml --cov
========================================================== test session starts ==========================================================
platform win32 -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
rootdir: C:\Users\ryanl\dev\azure_functions_coverage_test
plugins: cov-3.0.0
collected 2 items

tests\test_ClassB.py .                                                                                                             [ 50%]
tests\test_module_a.py .                                                                                                           [100%]

---------- coverage: platform win32, python 3.10.4-final-0 -----------
Coverage XML written to file cov.xml

=========================================================== 2 passed in 0.12s ===========================================================
(venv) PS C:\Users\ryanl\dev\azure_functions_coverage_test>

The key might have been to run the coverage report across the whole project. Let me know if that helps! py.test --cov-report xml:cov.xml --cov

ecormaksin commented 2 years ago

@ryanluker Thank you for your help!

I could color vscode editor by changing .vscode\settings.json as follows:

before:

    "--cov=DurableFunctionsHttpStart",
    "--cov=shared_code"

after:

    "--cov=."
ryanluker commented 2 years ago

@ecormaksin excellent! Happy coding 😁