Skip to content

Pytest Discovery Error #21757

Description

Type: Bug

Behaviour

Expected vs. Actual

Expected: Discover, run and debug tests
Actual: Python3 error (see output from Output panel below).

Steps to reproduce:

  1. Try to discover/run/debug tests

Everything works fine from the terminal using the same command (python -m pytest --collect-only tests) from the same cwd (./backend/). Tests also run fine using pytest, pytest -v, python -m pytest and python -m pytest tests

The project structure is as follows:

<PROJECT_ROOT>
  |-backend
  |  |-.pytest_cache
  |  |-tests
  |  |-models
  |  |-__pycache__
  |  |-venv
  |  |-data
  |  |-services
  |-frontend
  |-.git
  |-.vscode

The diagnostic data below shows virtual environment as Global despite the fact that I am using a virtual environment. I have since changed the value of python.defaultInterpreterPath to backend/venv/bin/python and the virtual environment is now being detected and I have changed the interpreter path to use it. However, this has made no difference to test discovery.

Additionally, I'd like to add that as a workaround I have installed the Python Test Explorer extension by the Little Fox Team as this at least allows me to debug tests which is the whole reason for me wanting to run tests from VS Code. I can debug tests using the inline buttons that the aforementioned extension shows in the editor. The test explorer itself is still broken.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.4
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
  • 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)

2023-08-04 12:46:15.980 [error] pytest test discovery error
 [Error: spawn /opt/homebrew/bin/python3 ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:285:19)
	at onErrorNT (node:internal/child_process:506:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:83:21)] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /opt/homebrew/bin/python3',
  path: '/opt/homebrew/bin/python3',
  spawnargs: [ '-m', 'pytest', '-p', 'vscode_pytest', '--collect-only', 'tests' ]
}

User Settings


languageServer: "Pylance"

testing
• cwd: "backend"
• pytestArgs: ["tests"]
• pytestEnabled: true

Extension version: 2023.14.0
VS Code version: Code 1.80.2 (2ccd690cbff1569e4a83d7c43d45101f817401dc, 2023-07-27T20:57:59.134Z)
OS version: Darwin arm64 22.6.0
Modes:

System Info
Item Value
CPUs Apple M1 Pro (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 4, 6, 7
Memory (System) 16.00GB (0.19GB free)
Process Argv --crash-reporter-id 9dabde45-0274-4158-bbba-eb1f02f0cefb
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931:30280409
vshan820:30294714
vstes263cf:30335440
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263:30792226
vscaac:30438847
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30803844
282f8724:30602487
f6dab269:30613381
showlangstatbar:30737416
vsctsb:30748421
03d35959:30757346
pythonfmttext:30731395
pythoncmv:30756943
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
gsofa:30804715
pythonnosmt12:30797651
pythonidxptcf:30805731
pythonnoceb:30805159
e537b577:30795824
dsvsc013:30795093
dsvsc014:30804076

Metadata

Metadata

Labels

area-testinginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions