Skip to content

Testing coverage is also testing for Python virtual environment #25661

Closed

Description

@senese

Type: Bug

The Test Explorer page is also looking for Python files inside virtual environment directory when using Run Tests with Coverage.

  1. Create a Python virtual environment
  2. Install pytest and pytest-cov
  3. Create some tests
  4. Run tests with coverage

The only workaround I found was to use the --cov option in pytestArgs on settings.json:

    "python.testing.pytestArgs": [
        "tests",
        "-vv",
        "--cov",
        "--cov-report=xml",
    ],

The "--ignore=.venv/" flag in pytestArgs is (ironically) ignored and it doesn't make a difference.

Evidence:
Image

VS Code version: Code 1.106.3 (bf9252a2fb45be6893dd8870c0bf37e2e1766d61, 2025-11-25T22:28:18.024Z)
OS version: Windows_NT x64 10.0.26200
Modes:
Remote OS version: Linux x64 6.6.87.2-microsoft-standard-WSL2

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 x 3696)
GPU Status 2d_canvas: enabled
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 31.95GB (10.28GB free)
Process Argv --crash-reporter-id 13251f26-99cc-44e7-95aa-f3ba35ca2abf
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu
OS Linux x64 6.6.87.2-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 x 0)
Memory (System) 15.59GB (8.89GB free)
VM 0%
Extensions (54)
Extension Author (truncated) Version
tsl-problem-matcher amo 0.6.2
vscode-chrome-extesion-manifest-json-schema cez 1.0.2
jupyter-keymap ms- 1.1.2
remote-ssh ms- 0.120.0
remote-ssh-edit ms- 0.87.0
remote-wsl ms- 0.104.3
vscode-remote-extensionpack ms- 0.26.0
remote-explorer ms- 0.5.0
remote-server ms- 1.5.3
material-icon-theme PKi 5.29.0
sqlite-viewer qwt 0.10.6
toml be5 0.6.0
markdown-emoji bie 0.3.1
ruff cha 2025.32.0
vscode-eslint dba 3.0.20
docker doc 0.18.0
githistory don 0.6.20
gitlens eam 17.7.1
vscode-html-css ecm 2.0.13
prettier-vscode esb 11.0.2
vscode-jest-runner fir 0.4.84
copilot-chat Git 0.33.5
vscode-github-actions git 0.28.2
vscode-pull-request-github Git 0.122.1
go gol 0.50.0
vscode-graphql-syntax Gra 1.3.8
vscode-test-explorer hbe 2.22.1
rest-client hum 0.25.1
rainbow-csv mec 3.23.0
vscode-containers ms- 2.3.0
vscode-docker ms- 2.0.0
vscode-language-pack-pt-BR MS- 1.107.2025121009
black-formatter ms- 2025.2.0
debugpy ms- 2025.16.0
flake8 ms- 2025.2.0
python ms- 2025.20.0
vscode-pylance ms- 2025.10.4
vscode-python-envs ms- 1.14.0
jupyter ms- 2025.9.1
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.3.0
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
extension-test-runner ms- 0.0.12
test-adapter-converter ms- 0.2.1
stats-bar njz 0.5.2
indent-rainbow ode 8.3.1
prisma Pri 31.1.0
sqlite-viewer qwt 0.10.6
vscode-xml red 0.29.0
vscode-yaml red 1.19.1
LiveServer rit 5.7.9
vscode-conventional-commits viv 1.26.0
markdown-all-in-one yzh 3.6.3

(2 theme extensions excluded)

A/B Experiments
vsliv368cf:30146710
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
aj953862:31281341
nes-set-on:31351930
6abeh943:31336334
envsactivate1:31353494
cloudbuttont:31379625
todos-1:31405332
3efgi100_wstrepl:31403338
trigger-command-fix:31379601
use-responses-api:31390855
6j29d282:31407606
afag3459:31428711
ec5jj548:31422691
terminalsuggestenabled:31431119
cmp-ext-treat:31426748
cp_cls_c_966_ss:31426491
copilot6169-t2000-control:31431385
c0683394:31419495
478ah919:31426797
ge8j1254_inline_auto_hint_haiku:31427726
nes-autoexp-30:31426651
a5gib710:31426879
38bie571_auto:31426784
cp_cls_c_1081:31433293
copilot-nes-oct-ctrl:31433598

Activity

  1. added
    confirmation pendingThe issue needs to be confirmed through a maintainer reproducing the bug.
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Dec 15, 2025
  2. eleanorjboyd commented on Dec 18, 2025

    @eleanorjboyd
    Member

    hm I do not get the same behavior- here is my folder that I was testing with. Can you try this and see?

    Archive.zip

  3. eleanorjboyd commented on Dec 18, 2025

    @eleanorjboyd
    Member

    Also here we append the --cov arg and set it to the root dir so you shouldn't need to include the arg unless you want to override the existing behavior we have: https://github.com/eleanorjboyd/vscode-python/blob/5f33bcee29f329e1d8d05f461e4a2665c36c3d65/python_files/vscode_pytest/run_pytest_script.py#L38

  4. senese commented on Dec 19, 2025

    @senese
    Author

    Hi Eleanor Boyd (@eleanorjboyd). I ran your tests here, it didn't read the virtual env. I installed my dependencies and also tried with the pytestArgs that I was using and still nothing. So I suspected that the problem was in my workspace and found the problem.

    Some time ago I updated the Python version of the project and didn't realized that I had two virtual environments .venv and venv directories. Only venv was active, so that is why .venv was being "tested".

    I'm sorry about this mistake. You can close the issue.

  5. eleanorjboyd commented on Jan 5, 2026

    @eleanorjboyd
    Member

    glad it got figured out! No worries and happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingconfirmation pendingThe issue needs to be confirmed through a maintainer reproducing the bug.info-neededIssue requires more information from poster

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions