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

pytest with python.testing.cwd leads to "file not found" on execution #12266

Closed
Flamefire opened this issue Jun 10, 2020 · 4 comments
Closed
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@Flamefire
Copy link

Flamefire commented Jun 10, 2020

Environment data

  • VS Code version: 1.45.1
  • Extension version (available under the Extensions sidebar): 2020.5.86398
  • OS and version: Linux Mint
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.4
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pyenv
  • Relevant/affected Python packages and their versions: pytest 5.4.3

Expected behaviour

Running a Python test (using pytest) via a Code Lense should run the correct test file while starting from inside the directory specified via python.testing.cwd

Actual behaviour

Execution fails as it tries to execute the test file with a path relative to the root dir not the cwd.

Steps to reproduce:

  1. Set "python.testing.cwd": "${workspaceFolder}/test" and make sure pytest is selected ("python.testing.pytestEnabled": true)
  2. Create a simple test/test_foo.py file containing any test, e.g.:
def test_foo():
  assert 1 == 1
  1. Run via code lense after test discovery via pytest

Logs

Error shown in the Output pane is:

Error: Error: cannot open file:///home/alex/project/test/test/test_foo.py. Detail: Unable to read file '/home/alex/project/test/test/test_foo.py' (Error: Unable to resolve non-existing file '/home/alex/project/test/test/test_foo.py')

Strangely using the "Run all tests" does work but it does show the same error after successfully running.

Use case: Python adds the CWD to PYTHONPATH which is unwanted in this case as it would pick up a wrong folder.

@Flamefire Flamefire added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jun 10, 2020
@brettcannon
Copy link
Member

Duplicate of #8678

@brettcannon brettcannon marked this as a duplicate of #8678 Jun 10, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jun 10, 2020
@Flamefire
Copy link
Author

Thanks. Haven't found it because the path is not ignored. It is used (CWD actually changed) which leads to the file not found

@simonmeggle
Copy link

I cannot see any relevance to #8678 because what I am seeing in @Flamefire's error (and I also have), is a wrong duplication of the test folder name:

/home/alex/project/test/test/test_foo.py

This error is not mentioned in this issue and in my case is not solvable e.g. with conftest.py.

(For anyone with the same problem: I went back to a VS Code Python version from 8/2020 and it worked again.)

@brettcannon
Copy link
Member

@simonmeggle please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants