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

Saving any python file clears user-generated files in the pytest cache #21197

Closed
vberlier opened this issue May 8, 2023 · 2 comments
Closed
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@vberlier
Copy link

vberlier commented May 8, 2023

Type: Bug

Behaviour

Expected vs. Actual

I'm using a pytest fixture to download and cache some file with the pytest.Cache api. In the minimal reproduction below the file is saved in .pytest_cache/d/demo/the_file.txt. However I noticed that the file gets re-downloaded way more often than expected. It turns out vscode is deleting the .pytest_cache/d/demo directory any time a python file is saved in the workspace.

Steps to reproduce:

Install pytest in a new virtualenv and create test_demo.py:

from pathlib import Path

import pytest

@pytest.fixture
def the_file(cache: pytest.Cache) -> Path:
    directory = cache.mkdir("demo")
    the_file = directory / "the_file.txt"

    if not the_file.is_file():
        print("create the file!")
        the_file.write_text("hello\n")

    return the_file

def test_foo(the_file: Path):
    assert the_file.read_text() == "not hello\n"

Run pytest once. Notice that the output shows create the file!.

Open the explorer you should see that .pytest_cache/d/demo/the_file.txt was created.

Run pytest again. Notice that as expected the test no longer outputs create the file!.

Now make a dummy modification to save the file test_demo.py.

Immediately after saving the .pytest_cache/d/demo directory disappears.

The log also shows that vscode is running a command to discover tests, with a suspicious --cache-clear argument:

[info] > ./.venv/bin/python ~/.vscode-server/extensions/ms-python.python-2023.8.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear
[info] cwd: .

If you try running pytest again you'll notice that the output shows create the file!.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.6
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
User Settings


languageServer: "Pylance"

linting
• enabled: false

formatting
• provider: "black"

testing
• pytestEnabled: true

Extension version: 2023.8.0
VS Code version: Code 1.78.0 (252e5463d60e63238250799aef7375787f68b4ee, 2023-05-03T20:09:00.748Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Sandboxed: No
Connection to 'wsl+Ubuntu' could not be established
Remote OS version: Linux x64 5.15.90.1-microsoft-standard-WSL2

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 8, 2023
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-testing labels May 11, 2023
@eleanorjboyd
Copy link
Member

Sorry I haven't said much more on this issue but I do realize this is a bug and will be fixing it. Thanks

@eleanorjboyd
Copy link
Member

We have gotten rid of all the arg editing with the rewrite so this should be fixed! Please comment if you are not seeing the fix on the rewrite and I can investigate. Thanks!

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Oct 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants