microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

Support sandboxed environment selection for testing frameworks (pytest, uinttest) #24119

Open timonviola opened 2 months ago

timonviola commented 2 months ago

The feature request is to explicitly declare, which virtual environment should be used for tests.

I have sandboxed environments:

During development I want to set:

"python.defaultInterpreterPath": "${workspaceFolder}/.venv/dev/bin/python"

However, in that case, tests cannot be discovered:

[error] /Users/timon/work/dagcellent/dagcellent/.venv/dev/bin/python: No module named pytest

As soon as I activate the test venv, discovery works.

Note that setting:

"python.testing.pytestPath": "${workspaceFolder}/.venv/test.py3.11/bin/pytest",

seems to have no effect.


My .venv looks like this:

.venv
├── my_package
├── dev
└── test.py3.11

I am using hatch, but this can easily be replicated with poetry or other:

[tool.hatch.envs.dev]
extra-dependencies = [
    "pre-commit == 3.7.*",
    "ruff == 0.4.4",
    "mypy == 1.10.*",
]

[tool.hatch.envs.dev.scripts]
install = "pre-commit install --hook-type commit-msg"

[tool.hatch.envs.test]
extra-dependencies = [
    "pytest >= 8.0.0",
    "pytest-cov",
    "pytest-mock >= 3.14.0",
]
icyitscold commented 1 month ago

➕ but I just want "python.testing.pytestPath" to work. I have custom pytest wrapper module that setups up paths so it's super frustrating that vscode has this setting but then ignores it

github-actions[bot] commented 3 weeks ago

Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.