-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Type: Bug
Behaviour
When setting "python.testing.cwd": "${workspaceFolder}/src" the testing of python code using the VSCode Testing feature does not work. The indicators for the tests are gray circles, not green ticks or red x. The discovery of tests works. Debugging a test does not work. I get this in Test Results:
Running tests (pytest): /Users/cornelius/Repositories/Debug-Pytest/tests/test_main.py::test_main[1-2-3]
Running test with arguments: --rootdir /Users/cornelius/Repositories/Debug-Pytest/src --override-ini junit_family=xunit1 --junit-xml=/var/folders/z3/mfjy6_6n4lb5lpr3wz1f009h0000gn/T/tmp-28532jOG4caOuJzkq.xml --capture no ./test_main.py::test_main[1-2-3]
Current working directory: /Users/cornelius/Repositories/Debug-Pytest/src
Workspace directory: /Users/cornelius/Repositories/Debug-Pytest
Run completed, parsing output
Error while running tests: 1-2-3
TypeError: Cannot read properties of undefined (reading 'length')
Error while running tests:
TypeError: Cannot read properties of undefined (reading 'length')
Finished running tests!
In the debug console it prints:
============================= test session starts ==============================
platform darwin -- Python 3.12.2, pytest-8.3.2, pluggy-1.5.0
rootdir: /Users/cornelius/Repositories/Debug-Pytest/src
configfile: ../pyproject.toml
plugins: hydra-core-1.3.2
collected 0 items
- generated xml file: /var/folders/z3/mfjy6_6n4lb5lpr3wz1f009h0000gn/T/tmp-28532jOG4caOuJzkq.xml -
============================ no tests ran in 0.00s =============================
ERROR: file or directory not found: ./test_main.py::test_main[1-2-3]
Removing "python.testing.cwd": "${workspaceFolder}/src" makes it work. However, I require the cwd to be set to src/ during testing.
Steps to reproduce:
Create a folder with this structure:
├── Debug-PyTest.code-workspace
├── pyproject.toml
├── src
│ ├── main.py
│ └── utils.py
└── tests
└── test_main.py
and fill with these contents:
src/main.py
from utils import super_print
def add(a, b):
return a + bsrc/utils.py
def super_print(a):
print(a + "!!!")tests/test_main.py
import pytest
from main import add
@pytest.mark.parametrize("a,b,expected", [(1, 2, 3), (2, 3, 5), (3, 4, 7)])
def test_main(a, b, expected):
assert add(a, b) == expectedDebug-PyTest.code-workspace
{
"folders": [
{
"path": ".",
"name": "Code"
},
{
"path": "/Users/cornelius/data",
"name": "Data"
}
],
}pyproject.toml
[tool.ruff]
line-length = 144
[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = "src"
addopts = ["--import-mode=importlib"].vscode/settings.json
{
"python.testing.pytestArgs": ["${workspaceFolder}/tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.cwd": "${workspaceFolder}/src"
}Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
Output Panel Empty:
Extension version: 2024.12.3
VS Code version: Code 1.92.1 (eaa41d57266683296de7d118f574d0c2652e1fc4, 2024-08-07T20:16:39.455Z)
OS version: Darwin arm64 23.5.0
Modes:
Connection to 'ssh-remote+7b22686f73744e616d65223a22544f52524e4f44453134227d' could not be established
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.2
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServersetting: Default
User Settings
Multiroot scenario, following user settings may not apply:
languageServer: "Pylance"
testing
• cwd: "<placeholder>"
• pytestArgs: "<placeholder>"
• pytestEnabled: true
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| autoDocstring - Python Docstring Generator | njpwerner.autodocstring | 0.6.1 |
| CodeSnap | adpyke.codesnap | 1.3.4 |
| CSV to Table | phplasma.csv-to-table | 1.4.0 |
| Data Wrangler | ms-toolsai.datawrangler | 1.6.0 |
| Dev Containers | ms-vscode-remote.remote-containers | 0.380.0 |
| Docker | ms-azuretools.vscode-docker | 1.29.2 |
| Duplicate action | mrmlnc.vscode-duplicate | 1.2.1 |
| Even Better TOML | tamasfe.even-better-toml | 0.19.2 |
| GitHub Copilot | GitHub.copilot | 1.222.0 |
| GitHub Copilot Chat | GitHub.copilot-chat | 0.18.1 |
| GitHub Pull Requests | GitHub.vscode-pull-request-github | 0.94.0 |
| GitLens — Git supercharged | eamodio.gitlens | 15.2.3 |
| JavaScript Debugger | ms-vscode.js-debug | 1.92.0 |
| JavaScript Debugger Companion Extension | ms-vscode.js-debug-companion | 1.1.3 |
| Jupyter | ms-toolsai.jupyter | 2024.7.0 |
| Jupyter Cell Tags | ms-toolsai.vscode-jupyter-cell-tags | 0.1.9 |
| Jupyter Keymap | ms-toolsai.jupyter-keymap | 1.1.2 |
| Jupyter Notebook Renderers | ms-toolsai.jupyter-renderers | 1.0.19 |
| Jupyter Slide Show | ms-toolsai.vscode-jupyter-slideshow | 0.1.6 |
| markdownlint | DavidAnson.vscode-markdownlint | 0.55.0 |
| pre-commit-vscode | MarkLarah.pre-commit-vscode | 0.1.0 |
| Prettier - Code formatter | esbenp.prettier-vscode | 11.0.0 |
| Project Manager | alefragnani.project-manager | 12.8.0 |
| Pylance | ms-python.vscode-pylance | 2024.8.1 |
| Python | ms-python.python | 2024.12.3 |
| Python Debugger | ms-python.debugpy | 2024.11.2024081401 |
| Python Environment Manager | donjayamanne.python-environment-manager | 1.2.4 |
| Rainbow CSV | mechatroner.rainbow-csv | 3.12.0 |
| Remote - SSH | ms-vscode-remote.remote-ssh | 0.113.1 |
| Remote - SSH: Editing Configuration Files | ms-vscode-remote.remote-ssh-edit | 0.86.0 |
| Remote - Tunnels | ms-vscode.remote-server | 1.5.2 |
| Remote Development | ms-vscode-remote.vscode-remote-extensionpack | 0.25.0 |
| Remote Explorer | ms-vscode.remote-explorer | 0.4.3 |
| Ruff | charliermarsh.ruff | 2024.40.0 |
| Table Visualizer for JavaScript Profiles | ms-vscode.vscode-js-profile-table | 1.0.9 |
| vscode-pdf | tomoki1207.pdf | 1.2.2 |
| WSL | ms-vscode-remote.remote-wsl | 0.88.2 |
System Info
| Item | Value |
|---|---|
| CPUs | Apple M3 Max (14 x 2400) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on 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_graphite: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | 2, 2, 2 |
| Memory (System) | 36.00GB (0.22GB free) |
| Process Argv | --crash-reporter-id 844bc983-d86d-4dff-8880-b640e9c511f1 |
| Screen Reader | no |
| VM | 0% |
Connection to 'ssh-remote+7b22686f73744e616d65223a22544f52524e4f44453134227d' could not be established
