Skip to content

python.testing.pytestPath does not work with test discovery. #19317

Closed

Description

Discussed in #19316

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.

Activity

  1. karthiknadig commented on Jun 16, 2022

    @karthiknadig
    Member

    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.

  2. changed the title [-]PyTest: **ModuleNotFoundError** inside `venv`[/-] [+]`python.testing.pytestPath` does not work with test discovery.[/+] on Jun 16, 2022
  3. ProfessorCode212 commented on Jun 16, 2022

    @ProfessorCode212
    Author

    Karthik Nadig (@karthiknadig) That's a pity. It's a bit of a nuisance to have to install pytest for every single project. Is there any other way?

  4. karthiknadig commented on Jun 16, 2022

    @karthiknadig
    Member

    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.

  5. added
    feature-requestRequest for new features or functionality
    and removed
    bugIssue identified by VS Code Team member as probable bug
    triage-neededNeeds assignment to the proper sub-team
    on Jun 16, 2022
  6. karthiknadig commented on Jun 16, 2022

    @karthiknadig
    Member

    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.

  7. ProfessorCode212 commented on Jun 16, 2022

    @ProfessorCode212
    Author

    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.

  8. ProfessorCode212 commented on Jun 16, 2022

    @ProfessorCode212
    Author

    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.

  9. ProfessorCode212 commented on Aug 14, 2022

    @ProfessorCode212
    Author

    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?

  10. brettcannon commented on Aug 15, 2022

    @brettcannon
    Member

    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.

  11. gschaffner commented on Aug 17, 2022

    @gschaffner

    Great to hear, thanks!

    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.

  12. ProfessorCode212 commented on Aug 17, 2022

    @ProfessorCode212
    Author

    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.

  13. brettcannon commented on Aug 17, 2022

    @brettcannon
    Member

    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.

  14. eleanorjboyd commented on Oct 30, 2023

    @eleanorjboyd

    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.

    Thanks!

  15. locked as resolved and limited conversation to collaborators on Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-testingbugIssue identified by VS Code Team member as probable bugcommunity askFeature request that the community expressed interest infeature-requestRequest for new features or functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions