I have pytest configured and working in VSCode, with automatic test discovery enabled.
But renaming a folder in the project that contains tests breaks both those tests and auto-discovery, instead producing a Pytest Discovery Error. How can I get the Testing to fully refresh – removing tests under the old folder name and adding those in the new name?
Simple steps to reproduce problem:
- Under project folder
hellois a folderfoocontainingx.pyandtest_x.py. - Open the VSCode Testing sidebar and configure to run pytest.
- Now the Testing pane shows the test hierarchy
hello >> foo >> test_x.py >> test_* - In the VSCode Explorer pane rename
footobar. - Refresh Testing >> Test Explorer, and/or re-run all tests.
Result:
- None of the tests under
hello >> foowork because there is nohello/foo. - I can't get
hello >> bar >> ...to appear in the Testing pane. - Test Explorer also contains a
Pytest Discovery Error [hello](with details pasted below).
How can I force the Testing configuration to refresh so that it removes the hello >> foo tests and adds the hello >> bar tests?
Verbose output after renaming foo to bar and refreshing/re-running tests:
Python interpreter path: ~\AppData\Local\Programs\Python\Python39\python.exe
> ~\AppData\Local\Programs\Python\Python39\python.exe -c "import pytest"
> ~\AppData\Local\Programs\Python\Python39\python.exe ~\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear foo
cwd: .
> ~\AppData\Local\Programs\Python\Python39\python.exe ~\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear foo
cwd: .
> ~\AppData\Local\Programs\Python\Python39\python.exe ~\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear foo
cwd: .
> ~\AppData\Local\Programs\Python\Python39\python.exe -m pytest --rootdir . --override-ini junit_family=xunit1 --junit-xml=~\AppData\Local\Temp\tmp-13840MhzPL4CPuKOe.xml ./foo
cwd: .
> ~\AppData\Local\Programs\Python\Python39\python.exe -m pytest --rootdir . --override-ini junit_family=xunit1 --junit-xml=~\AppData\Local\Temp\tmp-13840ITbhhDmK8Ah1.xml
cwd: .
> ~\AppData\Local\Programs\Python\Python39\python.exe ~\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear foo
cwd: .
[ERROR 2022-8-18 12:2:6.129]: Error discovering pytest tests:
[n [Error]: ============================= test session starts =============================
platform win32 -- Python 3.9.2, pytest-7.1.3, pluggy-1.0.0
rootdir: c:\Users\Me\VSCode\hello
collected 0 items
========================= no tests collected in 0.00s =========================
ERROR: file or directory not found: foo