kondratyev-nv / vscode-python-test-adapter

Python Test Adapter for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
MIT License
117 stars 27 forks source link

Error on additional workspace folders that do not have a virtual environment #283

Open MSLeiter opened 2 years ago

MSLeiter commented 2 years ago

I'm getting the following error with the Python Test adapter and Pytest: image

All the errors have a message like the following:

Test loading failed: Error: Error occurred during process execution: Error: spawn d:\code\mca_app\_simulink\.venv\Scripts\python.exe ENOENT
Error: Error occurred during process execution: Error: spawn d:\code\mca_app\_simulink\.venv\Scripts\python.exe ENOENT
    at ChildProcess.<anonymous> (c:\Users\Mike.Leiter\.vscode\extensions\littlefoxteam.vscode-python-test-adapter-0.7.1\out\src\processRunner.js:37:28)
    at Object.onceWrapper (events.js:422:26)
    at ChildProcess.emit (events.js:315:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

This is a workspace where I have added a bunch of reference folders that are not part of my code, but they have files I want to search, copy from, etc.

The extension is working great in Python folders that are properly setup for Pytest (though I don't really want it to run in folders that aren't part of this codebase - I don't see a way to stop it though). It appears for the errors that the Test Explorer is attempting to run pytest from a virtual environment in each folder. i.e. the Python Interpreter is setup as "./.venv" and therefore the Test Explorer is going to every folder in the workspace and running Python as though there must be a "./.venv" virtual environment in each folder. When it can't find the ./.venv/Scripts/python.exe file to run pytest with, it errors out.

Assuming this is the issue, I suggest a something like:

  1. In each workspace folder, check if the python executable exists as a file, if not, do not run discovery on that folder. It should probably display somehow that the folder was ignored - perhaps leave an entry for the folder in the list, but instead of a big, red error icon, add some neutral icon with a comment that the folder was ignored. If the user clicks on that row, it should still open the the output window where some additional details could be given (i.e. 'For folder "x", Python executable "y" could not be found. Skipping test discovery'.)
  2. Still give us an error (though a more understandable message would be great), but give us a way of turning off discovery for any given folder with a setting. Preferably, you could add folders to the list by just right-clicking them in the test explorer window and selecting a new option like "ignore this folder for test discovery in this workspace".

One or both of the above. I'd love to be able to quickly tell the test explorer to ignore several folders that I don't want it to discover tests in.

kondratyev-nv commented 2 years ago

@MSLeiter Thank you for the issue! Hm, maybe I'm missing something in your configuration, but the extension won't attempt to discover tests by default. Test discovery is triggered when one of the python.testing.unittestEnabled, python.testing.pyTestEnabled, or pythonTestExplorer.testFramework options is set. Is it possible that you see this error because you've enabled test discovery globally (e.g. in User settings or System settings)? Does it make sense for you to move this to the workplace settings?