Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JustMyCode doesn't work when debugging python tests through the GUI #21249

Closed
NicolasM-Forsk opened this issue May 15, 2023 · 11 comments · Fixed by #21426
Closed

JustMyCode doesn't work when debugging python tests through the GUI #21249

NicolasM-Forsk opened this issue May 15, 2023 · 11 comments · Fixed by #21426
Assignees
Labels
area-debugging area-testing bug Issue identified by VS Code Team member as probable bug verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@NicolasM-Forsk
Copy link

NicolasM-Forsk commented May 15, 2023

Type: Bug

Behaviour

Expected vs. Actual

I cannot disable "just my code" and debug tests through the GUI.
Also, [object Object] notification keeps popping

image
image

Steps to reproduce:

When I setup the "Python: Debug Tests" configuration in my code workspace (launch section) as stated in the documentation, then click on "Testing" tab, then "Debug test", the debugger always skips thirdparty code.
https://code.visualstudio.com/docs/python/testing#_debug-tests
The same happens with "Test: Debug Test at Cursor" command.
I would like "justMyCode" to be interpreted.

Note: I have uninstalled pytest-cov and coverage and I still have the problem.

Diagnostic data

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

2023-05-15 10:40:02.562 [info] Telemetry is disabled
2023-05-15 10:40:02.562 [info] Experiments are disabled, only manually opted experiments are active.
2023-05-15 10:40:02.562 [info] Test server listening.
2023-05-15 10:40:02.562 [info] Python interpreter path: ./.venv/bin/python
2023-05-15 10:40:03.301 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-05-15 10:40:03.402 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-05-15 10:40:03.402 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-05-15 10:40:03.402 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-05-15 10:40:03.402 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-05-15 10:40:03.403 [info] Send text to terminal: source /home/dev/projects/myproject/.venv/bin/activate
2023-05-15 10:40:04.268 [info] Starting Pylance language server.
2023-05-15 10:40:06.684 [info] > . ./.venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server/extensions/ms-python.python-2023.8.0/pythonFiles/printEnvVariables.py
2023-05-15 10:40:06.684 [info] shell: bash
2023-05-15 10:40:06.738 [info] > ./.venv/bin/python ~/.vscode-server/extensions/ms-python.python-2023.8.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear
2023-05-15 10:40:06.738 [info] cwd: .

User Settings


languageServer: "Pylance"

testing
• pytestEnabled: true

============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-6.2.4, py-1.11.0, pluggy-0.13.1
rootdir: /home/dev/projects/test
plugins: html-3.1.1, metadata-2.0.1
collected 1 item
......
Frame skipped from debugging during step-in.
Note: may have been skipped because of "justMyCode" option (default == true). Try setting "justMyCode": false in the debug configuration (e.g., launch.json).

Extension version: 2023.8.0
VS Code version: Code 1.78.1 (6a995c4f4cc2ced6e3237749973982e751cb0bf9, 2023-05-04T09:48:08.683Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Sandboxed: No
Remote OS version: Linux x64 5.15.90.1-microsoft-standard-WSL2

System Info
Item Value
CPUs Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz (16 x 2904)
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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.72GB (12.32GB free)
Process Argv
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu-20.04
OS Linux x64 5.15.90.1-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz (16 x 2904)
Memory (System) 9.72GB (6.40GB free)
VM 0%
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 15, 2023
@NicolasM-Forsk NicolasM-Forsk changed the title JustMyCode doesn't work in python tests JustMyCode doesn't work when debugging python tests through the GUI May 15, 2023
@paulacamargo25
Copy link

Hi @NicolasM-Forsk, can you send me your launch.json config? Thanks

@github-actions github-actions bot added the info-needed Issue requires more information from poster label May 15, 2023
@nmoreaud
Copy link

test.code-workspace:

{
    "folders": [
        {
            "path": "/home/dev/projects/test"
        }
    ],
    "settings": {
        "python.testing.pytestEnabled": true
    },
    "launch": {
        "configurations": [
            {
                "name": "Python: Debug Tests",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "purpose": ["debug-test"],
                "console": "integratedTerminal",
                "justMyCode": false
            }
        ]
    }
}

@nmoreaud
Copy link

nmoreaud commented May 19, 2023

Here is a simple example project to reproduce the "bug": sample.zip
The goal here is to be able to step in json.dumps
Setup:

python3 -m venv .venv
source .venv/bin/activate
pip install pytest

@paulacamargo25 paulacamargo25 removed the info-needed Issue requires more information from poster label May 24, 2023
@paulacamargo25
Copy link

Thanks @nmoreaud for the reply, I was able to reproduce the issue, what happens is that we are only reading the config from the launch.json file fro tests.

We will be fixing it in the next iteration, what you can do in the meantime is put that same configuration in the launch.json file and it will work.

Thank you

@paulacamargo25 paulacamargo25 added needs PR Ready to be worked on area-debugging and removed triage-needed Needs assignment to the proper sub-team labels Jun 2, 2023
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jun 2, 2023
@paulacamargo25 paulacamargo25 added area-testing bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Jun 2, 2023
@starball5
Copy link

@nmoreaud
Copy link

nmoreaud commented Jun 2, 2023

Note: creating a separate launch.json file is a nice workaround, but it comes with a drawback.
When a test is being debugged, click on restart (Ctrl+Shift+F5) has broken behavior (no module named myproject).

Here is what happens:

  • First call: the test is debugged with some pytest options taken from the workspace.
    Debugger is paused on a breakpoint
/usr/bin/env /home/dev/projects/myproject/.venv/bin/python /home/dev/.vscode-server/extensions/ms-python.python-2023.8.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 40867 -- /home/dev/.vscode-server/extensions/ms-python.python-2023.8.0/pythonFiles/testlauncher.py /home/dev/projects/myproject pytest --rootdir /home/dev/projects/myproject --override-ini junit_family=xunit1 --junit-xml=/tmp/tmp-230583JUOHkY7ekio.xml -v -s -rsx ./myproject/test/test.py::TestClass::test_fn 
  • Restart debugging: runs debugger on current file (where there is a breakpoint), not restarting pytest debugging
cd /home/dev/projects/myproject ; /usr/bin/env /home/dev/projects/myproject/.venv/bin/python /home/dev/.vscode-server/extensions/ms-python.python-2023.8.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 57363 -- /home/dev/projects/myproject/myproject/somecode.py 

@paulacamargo25
Copy link

Hi @nmoreaud thanks for the bug report, Could you create a new issue with this other error? This issue will be about the previous one.

Thanks

@nmoreaud
Copy link

nmoreaud commented Jun 5, 2023

Ok, I opened this other issue: #21365

@paulacamargo25
Copy link

paulacamargo25 commented Jun 27, 2023

Verification steps:

  • Setup the "Python: Debug Tests" configuration in the code workspace. with the value:
{
    "folders": [
        {
            "path": "/home/dev/projects/test"
        }
    ],
    "settings": {
        "python.testing.pytestEnabled": true
    },
    "launch": {
        "configurations": [
            {
                "name": "Python: Debug Tests",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "purpose": ["debug-test"],
                "console": "integratedTerminal",
                "justMyCode": true
            }
        ]
    }
}
  • Run the tests, and make sure that the value in justMyCode is used.

@andreamah andreamah added verified Verification succeeded and removed verified Verification succeeded labels Jun 28, 2023
@andreamah
Copy link

Hi @paulacamargo25! For verification, could you provide some test file content that I could test with? Also, how would I know that justMyCode is used?

@rzhao271 rzhao271 added the verified Verification succeeded label Jun 28, 2023
@rzhao271 rzhao271 removed the verified Verification succeeded label Jun 28, 2023
@paulacamargo25
Copy link

paulacamargo25 commented Jun 28, 2023

Sure, you can try with test-issue-21249.zip. justMyCode allows you to specify if you want to debug only your code (justMyCode=true) or if you want to also debug the code of the libraries you use (justMyCode=false). By defaull is true.

  1. Create a venv.
  2. pip install pytest.
  3. Check that the value of justMyCode=false.
  4. Run the test with a breakpoint in assert json.dumps({'toto': 'tata'}) == "{'toto': 'tata'}".
  5. Check that the step in json.dumps works, and open the code for it.

@rzhao271 rzhao271 added the verified Verification succeeded label Jun 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2023
@eleanorjboyd eleanorjboyd removed the needs PR Ready to be worked on label Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging area-testing bug Issue identified by VS Code Team member as probable bug verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants