pythonvisual-studio-codecoverage.py

The coverage run icon in the Test Explorer is not displayed in Visual Studio Code


The coverage run icon in the Test Explorer is not displayed in Visual Studio Code. Check snapshot. Is There a way to enable coverage on Visual Code interface? I'm using Python pytest and working remotely on a Linux Ubuntu server using Remote-SSH extension. I'm attaching a snapshot of the Testing selection and the 'Settings.json' I have.

Snapshot of testing selection on VC.

{
"python.analysis.autoImportCompletions": true,
"python.analysis.fixAll": ["source.unusedImports"],  
"editor.defaultFormatter": "charliermarsh.ruff",
"files.exclude": {
    "**/__pycache__": true,
    "**/.cache": true,
    "**/.coverage": true,
    "**/.coverage.*": true,
    "**/.hypothesis": true,
    "**/.mypy_cache": true,
    "**/.nox": true,
    "**/.pytest_cache": true,
    "**/.ruff_cache": true,
    "**/.tox": true
},
"python.testing.pytestEnabled": true

}


Solution

  • Check whether pytest-cov is installed.

    Add "python.experiments.optInto": ["pythonTestAdapter"] in user settings.json. After the plugin is installed, clear python project cache, restart the python extension.

    Also check to update VS Code. I had this problem in an older version.

    For your reference:

    https://code.visualstudio.com/docs/python/testing#_run-tests-with-coverage