vscode-python: Pytest test discovery over SSH does not work

Type: Bug

Behaviour

Pytest test discovery does not find any test inside the VS Code python extension when working on a remote machine with the Microsoft SSH Remote extension. No error is reported in the OUTPUT/PYTHON window. Indeed, when I copy and paste the command from OUTPUT/PYTHON in the terminal, it finds the tests just fine. Similarly, when I run pytest --collect-only from the terminal, it finds the test just fine. I have double checked the configuration and that all subfolders have __init__.py . Indeed, I have tried moving the test files to different places, including right in the folder (not in any subfolder) configured in settings.json and still no test is discovered.

However, it works well without the SSH remote extension.

Expected vs. Actual

I expect the tests to be discovered, or an output error to be displayed in OUTPUT/PYTHON window. However, no test is discovered and no error is displayed, as described above.

Moreover, I would expect OUTPUT/PYTHON to display the same output as when I run the command in the terminal: ~/venvs/my_repo/bin/python ~/.vscode-server/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear my_src_folder_with_tests

Interestingly, when I force a bug in one of the tests (like adding a random character after the brakedts in the test definition), the error is catched and displayed in OUTPUT/PYTHON. But when I fix the bug, no error is displayed as expected, but the tests are not discovered.

Steps to reproduce:

  1. Connect to the remote machine over ssh and open the folder with the repo.
  2. Create test_fake.py file inside the src_with_test folder configured in "python.testing.pytestArgs".
  3. Be sure src_with_test has an __init__.py file, and that test_fake.py has a valid test, like:
test_one():
    assert True
  1. Configure pytest (ctrl + shift + p) or in settings.json:
{
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.testing.pytestArgs": [
        "humanmodelling"
    ]
}
  1. Open the Testing panel and click refresh discovery.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.0
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

User Settings


languageServer: "Pylance"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true

Extension version: 2022.14.0 VS Code version: Code 1.71.2 (74b1f979648cc44d385a2286793c226e611f59e7, 2022-09-14T21:03:37.738Z) OS version: Windows_NT x64 10.0.22621 Modes: Sandboxed: No Remote OS version: Linux x64 5.4.0-1090-azure

System Info
Item Value
CPUs 11th Gen Intel® Core™ i7-1185G7 @ 3.00GHz (8 x 2995)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 31.84GB (16.53GB free)
Process Argv –crash-reporter-id c7209560-d4e0-4b0b-af53-21d213e1c4a6
Screen Reader no
VM 0%
Item Value
Remote SSH: sergiov-vm-nc6sv3
OS Linux x64 5.4.0-1090-azure
CPUs Intel® Xeon® CPU E5-2690 v4 @ 2.60GHz (6 x 2593)
Memory (System) 110.06GB (107.62GB free)
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30557514
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
hb751961:30553087
dsvsc012:30540252
azure-dev_surveyone:30548225
2144e591:30553903
fc301958:30567733

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 22 (11 by maintainers)

Most upvoted comments

I’m seeing the same thing.

Tests discovered locally and in WSL, but not in the Linux remote.

The odd thing is that the Python log shows the following command being executed which when I run directly in the shell does indeed produce results.

./.venv/bin/python <my-home>/.vscode-server/extensions/ms-python.python-2023.2.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear -c ./pytest.ini tests