Home > Back-end >  Visual Studio Code (VS Code) Run Test button works fine but Debug Test does not
Visual Studio Code (VS Code) Run Test button works fine but Debug Test does not

Time:06-25

VS Code works just fine when Run Test button (does not matter if via testing tab (left side) or by right click close to the test) but Debug Test button logs this error:

.
.
.
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/testlauncher.py", line 44, in <module>
    run(cwd, testRunner, args)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/testlauncher.py", line 34, in run
    import pytest
ModuleNotFoundError: No module named 'pytest'

settings.json

{
    "python.testing.pytestArgs": [
        "packages/xxxxxx/tests/unit/xxxxxx/xxxxx",
        "-s",
    ],
    "python.testing.pytestPath": "runtimes/.venv/xxxxxx/bin/pytest",
    "python.testing.pytestEnabled": true,
    "python.linting.pylintEnabled": false,
    "python.linting.enabled": false,

    "files.exclude": {
        "**/*.pyc": true,
    }
}

I went through this link: Tried the below suggestions, without any luck:

  1. Downgrade the Python extention to v2020.2.64397
  2. Include these lines into launch.json:
{
     "name": "Python: Test debug config",
     "type": "python",
     "request": "test",
     "console": "integratedTerminal",
     "logToFile": true
}

CodePudding user response:

You can specify the python interpreter by adding the following code to launch.json:

"python": "your python path"#for example "/AppData/Local/Programs/Python/Python310/python.exe"

CodePudding user response:

For me I found the solution was to not include pytest-cov coverage testing during local debug testing.

pytest-cov docs

This thread has the background on the issue.

https://github.com/microsoft/vscode-python/issues/693

  • Related