Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
timonviola opened this issue Sep 17, 2024 · 4 comments
Assignees
Labels
area-testing community ask Feature request that the community expressed interest in feature-request Request for new features or functionality info-needed Issue requires more information from poster needs PR Ready to be worked on

Comments

@timonviola
Copy link

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

I have sandboxed environments:

  • project dependecies (used for editable installs, etc.)
  • dev (used during development)
  • test (used for tests)

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",
]
@timonviola timonviola added the feature-request Request for new features or functionality label Sep 17, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 17, 2024
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug and removed feature-request Request for new features or functionality labels Sep 17, 2024
@icyitscold
Copy link

➕ 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

@eleanorjboyd eleanorjboyd added feature-request Request for new features or functionality area-testing needs community feedback Awaiting community feedback community ask Feature request that the community expressed interest in and removed bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Oct 30, 2024
Copy link

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.

@dacevedo12
Copy link

Same here, custom pytest wrapper. Looks like this extension runs everything using https://github.com/microsoft/vscode-python/blob/main/python_files/vscode_pytest/run_pytest_script.py and doesn't take that config at all

@eleanorjboyd
Copy link
Member

Hi! Quick question- anyone know how I can specify which pytest if I am using pytest.main()? I was looking into this issue and yes you are right that "python.testing.pytestPath" so I am trying to get that value to be used but cannot figure out how to use it here:

pytest.main(arg_array)
except Exception as e:
. Currently spinning up a subprocess is not an option as we hit another error if a subprocess is run with too many test ids which is fixed by called pytest.main()

@eleanorjboyd eleanorjboyd added info-needed Issue requires more information from poster needs PR Ready to be worked on and removed needs community feedback Awaiting community feedback labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-testing community ask Feature request that the community expressed interest in feature-request Request for new features or functionality info-needed Issue requires more information from poster needs PR Ready to be worked on
Projects
None yet
Development

No branches or pull requests

5 participants