0

After trying all solutions online (like reinstalling python, checking if discovery works from the terminal, adding or removing __init__.py files, deleting all __pycache__ folders,...) VSC still doesn't discover any test and, what's worse, there is no error message or anything... simply silent failing. Pytest, from the command line, works as expected.

VSC runs the following command (which doesn't add any test or recognizes any in the UI):

conda run -n azureml_py38 --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear

When I run it in my terminal, I get:

>>>PYTHON-EXEC-OUTPUT

[{"rootid": ".", "root": "/mnt/batch/tasks/.../PROJECTFOLDER", "parents": [{"id": "./tests", "kind": "folder", "name": "tests", "parentid": ".", "relpath": "./tests"}, {"id": …

<<<PYTHON-EXEC-OUTPUT

so it looks as if the command is right and the tests can be discovered. My folder structure is simple:

 ├─.vscode/
 │    └─ settings.json
 ├─src/
 │  ├─ __init__.py
 │  └─ module_A/
 │       ├─ __init__.py
 │       └─ code.py
 └─tests/
    ├─ __init__.py
    └─ unit_tests/
         └─ test_code.py

My settings.json is basically:

 {
     "python.testing.unittestEnabled": false,
     "python.testing.pytestEnabled": true,
     "python.envFile": "${workspaceFolder}/.env"
 }

and in my .env file there's only PYTHONPATH=.

My versions are:

  1. vscode version: 1.71.2
  2. pytest version: 7.1.0
  3. python extension version: v2022.14.0

Any ideas?

Jzbach
  • 346
  • 3
  • 17
  • Can [docs](https://code.visualstudio.com/docs/python/testing#_test-discovery) help? – MingJie-MSFT Sep 26 '22 at 05:17
  • Sadly no, I actually forgot to mention that I started with the docs and only the, when the problems started, I started googling and checking here. – Jzbach Sep 26 '22 at 08:48
  • Can project created following the documentation example be discovered by pytest? – MingJie-MSFT Sep 26 '22 at 08:50
  • Yep, it can be discovered as well as when I do it from the terminal. Somehow is VSC not properly configured or simply it doesn't find the tests. The only last ressource option I can think of, is reinstalling VSC... – Jzbach Sep 26 '22 at 08:53
  • After a long time, I found out that VSC cannot resolve simlinks. When the project is opened at it's absolute path, pytests finds out everything! – Jzbach Apr 12 '23 at 13:32

0 Answers0