Home > Mobile >  VS Code pytest can't find any tests in workspace
VS Code pytest can't find any tests in workspace

Time:01-27

I am trying to migrate my python project from pycharm to vs code. I have PyTest setup in vs-code but none of the tests are being found even though running pytest from the command line works fine. On the left side in the "Testing" section where should be project tests I am getting the error: "ModuleNotFoundError: No module named 'YADAYADA'", maybe somebody knows how to fix this?

I have tried to add init.py file to every folder and subfolder

CodePudding user response:

Vscode uses the currently open folder as the workspace. You need to open your project folder with vscode. In addition, you also need to install necessary extensions for it, such as enter image description here

Read the documentation for details.

CodePudding user response:

Found out why it is not collecting tests, the main reason is that, because tests are written in one folder and I am trying to import a module from another level folder and vs-code trying to find that module in the same folder as the test file. So this info with PYTHONPATH helped me: https://www.geeksforgeeks.org/python-import-module-from-different-directory/

  • Related