You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
python.testing.pytestPath does not work with test discovery. #19317
Originally posted by ProfessorCode212 June 16, 2022
I get the following uncaught error for the Python Extension in VS Code. This only happens inside venv. It doesn't seem to be able to detect my system-wide pytest installation. I have even set python.testing.pytestPath to ~/.local/bin/pytest.
Traceback (most recent call last):
File "/home/pc/.vscode/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/run_adapter.py",
line 17, in <module> from testing_tools.adapter.__main__ import parse_args,
main File "/home/pc/.vscode/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/__main__.py",
line 9, in <module> from . import pytest,
report File "/home/pc/.vscode/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/__init__.py",
line 7, in <module> from ._discovery import discover
File "/home/pc/.vscode/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py",
line 8, in <module> import pytest
ModuleNotFoundError: No module named 'pytest'
This problem does get fixed if I install pytest into the relevant venv but I am wondering if there is a way around it.
python.testing.pytestPath is not supported very well in the extension. Actually, there are plans to remove it entirely. Installing it in the venv is the right thing to do here.
changed the title [-]PyTest: **ModuleNotFoundError** inside `venv`[/-][+]`python.testing.pytestPath` does not work with test discovery.[/+]on Jun 16, 2022
Unfortunately, there is no other way. The reason is that often tools like linter, formatter etc are not really tied too tightly to the projects. So there was some demand to use those tools from a global location. But pytest is often used with additional plugins which require and sometimes work with specific version of pytest. So, there has been little to no demand to use a global pytest.
I can turn this into a feature request and see how the demand is.
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.
But pytest is often used with additional plugins which require and sometimes work with specific version of pytest. So, there has been little to no demand to use a global pytest.
🤔 Isn't that the point of giving this option, though? Anyone who wants to use a project-specific version of pytest can just leave python.testing.pytestPath as is and use a venv. Others can opt to use a globally-installed pytest package.
At the very least, I hope there could be a notification that advises users to install pytest in the current environment rather than just producing uncaught errors. The message should also be visible in the Testing section of the sidebar.
Karthik Nadig (@karthiknadig) It's just under two months from when this issue was first created and there are more than 7 upvotes for this issue. Will this feature be added to your roadmap now?
Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.
We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most.
And just an FYI, I go through all issues waiting for votes 60 days after we asked for votes/feedback (rounded up by week), so there's no need to flag us as we will notice the vote count.
Should this be categorized as a bug rather than as a feature request? The docs state that python.testing.pytestPath should work for a pytest executable not installed under the current interpreter:
python.testing.pytestPath: Path to pytest. Use a full path if pytest is located outside the current environment [ref].
Other similar options (python.linting.flake8Path, python.formatting.blackPath, etc.) do not have this issue.
Ganden Schaffner (@gschaffner) I believe they are currently trying to deprecate it, which is why this is categorized as a 'feature request'. I agree, though, that this is a bug since there is no warning given for it and the setting is still half there in VS Code.
Ganden Schaffner (@gschaffner) the classification won't really affect how we address it since we are actively working on the testing code rewrite for pytest. I don't think stopping that work to try and implement this or rip it out by treating like a bug is going to be the best use of anyone's time on the team. If someone would like to propose a solution and submit a PR in the mean time, we would be willing to review it.
Hello! I have reviewed this issue and have tested a similar scenario successfully on our testing rewrite. Therefore I am going to close this issue but please comment or open a new issue if you are still seeing a problem when you try this yourself!
To use the rewrite yourself just add ”python.experiments.optInto": ["pythonTestAdapter"] to your user settings. You can confirm you have the rewrite enabled by setting your log level to trace, via the Developer: Set Log Level command in the command palette. Then check to see if Experiment 'pythonTestAdapter' is active is in your python logs.
Activity
karthiknadig commentedon Jun 16, 2022
python.testing.pytestPathis not supported very well in the extension. Actually, there are plans to remove it entirely. Installing it in thevenvis the right thing to do here.[-]PyTest: **ModuleNotFoundError** inside `venv`[/-][+]`python.testing.pytestPath` does not work with test discovery.[/+]ProfessorCode212 commentedon Jun 16, 2022
Karthik Nadig (@karthiknadig) That's a pity. It's a bit of a nuisance to have to install
pytestfor every single project. Is there any other way?karthiknadig commentedon Jun 16, 2022
Unfortunately, there is no other way. The reason is that often tools like linter, formatter etc are not really tied too tightly to the projects. So there was some demand to use those tools from a global location. But pytest is often used with additional plugins which require and sometimes work with specific version of pytest. So, there has been little to no demand to use a global pytest.
I can turn this into a feature request and see how the demand is.
karthiknadig commentedon Jun 16, 2022
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.
ProfessorCode212 commentedon Jun 16, 2022
🤔 Isn't that the point of giving this option, though? Anyone who wants to use a project-specific version of
pytestcan just leavepython.testing.pytestPathas is and use avenv. Others can opt to use a globally-installedpytestpackage.ProfessorCode212 commentedon Jun 16, 2022
At the very least, I hope there could be a notification that advises users to install
pytestin the current environment rather than just producing uncaught errors. The message should also be visible in the Testing section of the sidebar.ProfessorCode212 commentedon Aug 14, 2022
Karthik Nadig (@karthiknadig) It's just under two months from when this issue was first created and there are more than 7 upvotes for this issue. Will this feature be added to your roadmap now?
brettcannon commentedon Aug 15, 2022
Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.
We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most.
And just an FYI, I go through all issues waiting for votes 60 days after we asked for votes/feedback (rounded up by week), so there's no need to flag us as we will notice the vote count.
gschaffner commentedon Aug 17, 2022
Great to hear, thanks!
Should this be categorized as a bug rather than as a feature request? The docs state that
python.testing.pytestPathshould work for a pytest executable not installed under the current interpreter:Other similar options (
python.linting.flake8Path,python.formatting.blackPath, etc.) do not have this issue.ProfessorCode212 commentedon Aug 17, 2022
Ganden Schaffner (@gschaffner) I believe they are currently trying to deprecate it, which is why this is categorized as a 'feature request'. I agree, though, that this is a bug since there is no warning given for it and the setting is still half there in VS Code.
brettcannon commentedon Aug 17, 2022
Ganden Schaffner (@gschaffner) the classification won't really affect how we address it since we are actively working on the testing code rewrite for pytest. I don't think stopping that work to try and implement this or rip it out by treating like a bug is going to be the best use of anyone's time on the team. If someone would like to propose a solution and submit a PR in the mean time, we would be willing to review it.
Regardless, I've added the bug label as well.
eleanorjboyd commentedon Oct 30, 2023
Hello! I have reviewed this issue and have tested a similar scenario successfully on our testing rewrite. Therefore I am going to close this issue but please comment or open a new issue if you are still seeing a problem when you try this yourself!
To use the rewrite yourself just add
”python.experiments.optInto": ["pythonTestAdapter"]to your user settings. You can confirm you have the rewrite enabled by setting your log level to trace, via theDeveloper: Set Log Levelcommand in the command palette. Then check to see ifExperiment 'pythonTestAdapter' is activeis in your python logs.Thanks!