vscode-python: Discovery works but execution fails with file not found error

Hello,

I didn’t seem to have this problem before, but something seems to have gone a bit wonky this week (no changes to config on my end). Using the vscode Testing pane, I’m seeing tests successfully discovered, but if i try to run (or debug them), they automatically fail with a

ERROR: file or directory not found: <package/module/submodule_1/submodule_2/tests/test_file.py>

Our layout is a bit interesting, but at a high level it’s something like

repo\
    lib\
        package\

The terminal spawns at repo, but I have an .env file with PYTHONPATH=lib. All this seemed to have worked until say… Thursday? 😃 . Perhaps I had it setup wrong. In the debug output, I do see it now showing: Recieved JSON data: [package/module/submodule_1/submodule_2/tests/test_file.py::tests_blahblah

I’ve never seen that Received JSON line before; i do wonder if something on the paths is getting a little messed up from the latest version? Apologies for the mediocre output trace; trying to abstract it as much as I can. Let me know what else I could do to be helpful?

I’m using v2023.12.0.

And of course running something like pytest lib\package\module\submodule_1\submodule_2\tests\test_file.py works perfectly fine from terminal!

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 29 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@juandiago downgraded extension version from 2023.12 to 2023.8 and I can verify that it works again, thanks 😃

Can confirm resolved, everything green & working

Hi @eleanorjboyd! To my understanding it was fixed and that’s why I closed it.

karev0 - Awesome! I installed the 2023.08 and everything works. This will do for now i suppose

Good catch @juandiago, thanks! Yes, the fix was reverted due to an error that appeared in the testing behavior but this commit was not actually the culprit so we will be re-merging it soon. Thanks

I can confirm this same issue on my end with versions above 2023.8.0, had to pin the extension version to 2023.8.0 on my devcontainer.json to be able to work with the Testing panel again. Looks like a regression got introduced on releases after 2023.8.0.

From early investigation, seems like pytest’s rootdir is getting changed between the discovery phase and the run phase of the tests.

pytest.ini

[pytest]
DJANGO_SETTINGS_MODULE = app.settings
pythonpath = . src
env =
    ENV=test
addopts = -v --color=yes -p no:warnings