forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
area-testingfeature-requestRequest for new features or functionalityRequest for new features or functionalitytriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
Description
Note: I could not get the Issue Reporter to work in vscode, so I had to use the feature-request link to create this.
Behaviour
In Python 3.12 and above, when debugging tests, the "justMyCode": false setting is ignored.
Steps to reproduce:
- install pytest and an external library in a virtual environment using python 3.12 or 3.13 (in my example below I used
requests) - Create a file called
test_external_library.pyand create a simple function that calls the external library - Create a simple test that calls your function
- Set a breakpoint in the external library
- create a launch.json config for debug-test that includes justMyCode set to false.
- Run the test using one of the interfaces in vscode.
- Observe that in python 3.12 or 3.13 the breakpoint is ignored. In python 3.11 (and previous), the debugger stops at the breakpoint inside the external library.
Note: this occurs with python installations using uv, conda and homebrew.
Example test_external_library.py:
import requests
def get_example():
r = requests.get("https://example.com")
return r.text
def test_get_example():
assert "Example Domain" in get_example()In this situation, I set a breakpoint inside the requests get function (inside api.py)
launch.json config:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Tests",
"type": "debugpy",
"request": "launch",
"purpose": [
"debug-test"
],
"justMyCode": false,
"console": "integratedTerminal"
}
]
}Diagnostic data
Output for Python in the Output panel (ViewβOutput, change the drop-down the upper-right of the Output panel to Python)
2024-11-13 17:22:40.236 [warning] Dir "/Users/bfalk/repos/advent-of-code/.pixi/envs" is not watchable (directory does not exist)
2024-11-13 17:22:40.236 [info] Python interpreter path: ./.venv/bin/python
2024-11-13 17:22:40.249 [info] > pyenv which python
2024-11-13 17:22:40.249 [info] cwd: .
2024-11-13 17:22:41.360 [info] Starting Pylance language server.
2024-11-13 17:36:19.069 [info] Discover tests for workspace name: advent-of-code - uri: /Users/bfalk/repos/advent-of-code
2024-11-13 17:36:19.089 [info] > . ./.venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/printEnvVariables.py
2024-11-13 17:36:19.089 [info] shell: bash
2024-11-13 17:36:19.252 [info] > ./.venv/bin/python ~/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests
2024-11-13 17:36:19.252 [info] cwd: .
2024-11-13 17:36:26.597 [info] > ./.venv/bin/python -m pytest --rootdir . --override-ini junit_family=xunit1 --junit-xml=/var/folders/d5/7lllrg_s1238gsx2j2ng9bqw0002h3/T/tmp-34581rKova1P4u5CN.xml ./tests/test_requests.py::test_get_example
2024-11-13 17:36:26.597 [info] cwd: .
2024-11-13 17:36:31.841 [info] Using configuration in launch.json
2024-11-13 17:36:32.054 [info] CreateEnv Trigger - Skipping for /Users/bfalk/repos/advent-of-code
2024-11-13 17:36:32.157 [info] Send text to terminal: source /Users/bfalk/repos/advent-of-code/.venv/bin/activate
2024-11-13 17:36:32.706 [info] Send text to terminal: /usr/bin/env /Users/bfalk/repos/advent-of-code/.venv/bin/python /Users/bfalk/.vscode/extensions/ms-python.debugpy-2024.13.2024111101-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher 49669 -- /Users/bfalk/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/testlauncher.py /Users/bfalk/repos/advent-of-code pytest --rootdir /Users/bfalk/repos/advent-of-code --override-ini junit_family=xunit1 --junit-xml=/var/folders/d5/7lllrg_s1238gsx2j2ng9bqw0002h3/T/tmp-34581xrpDKxB2YyK2.xml --capture no ./tests/test_requests.py::test_get_example
brent-spyder, Isaben, alexwilson1, lukaszkadlubowski, EuleMitKeule and 2 more
Metadata
Metadata
Assignees
Labels
area-testingfeature-requestRequest for new features or functionalityRequest for new features or functionalitytriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team