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

"Debug test" unable to attach to subprocesses or or existing processes #461

Open
rwarren opened this issue Sep 21, 2024 · 1 comment
Open
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@rwarren
Copy link

rwarren commented Sep 21, 2024

When using the "Debug Test" functionality in VSCode with Python, I am unable to get the debugger to attach to subprocesses spawned during the tests. I've set "subProcess": true in my launch.json file and included "purpose": ["debug-test"], which seems like what I am suppose dto do to configure "debug test" launches... but this doesn't seem to have any effect -- the debugger still doesn't attach to subprocesses.

Additionally, I have tried to use the "connect" option to attach to an existing process, but VSCode doesn't allow the "connect" attribute at all when "purpose" includes "debug-test".

I've prepared a simple project to demonstrate the issue:

https://github.com/rwarren/DEMO_vscode_subprocess_debug

Details:

  1. The test suite starts a subprocess that needs to be debugged
    • Although I would also like to (and prefer to) be able to attach to an already running subprocess to save startup time when iterating on test code vs application code
  2. The launch.json configuration includes "subProcess": true, but subprocess debugging doesn't work during "Debug Test" runs
  3. vscode does not allow "connect" when "purpose": ["debug-test"] is set, limiting this option as well

What I'm hoping for here:

  1. Guidance on how to enable subprocess debugging when running tests with "Debug Test".
    • i.e. am I just doing this wrong?
  2. Clarification on whether this is a limitation of the current debugger implementation.
    • i.e. is this just not possible?
  3. Suggestions for workarounds to debug subprocesses in tests
    • e.g. I am considering running two vscode instances, one that debugs the server, an da second that debugs the tests... but this is obviously not-ideal
@eleanorjboyd
Copy link
Member

Hi! If I understand correctly you are running tests, these tests run a subprocess, you are attempting to attach to this subprocess? Since you are just attaching to this subprocess, I don't think you will need the type to be "purpose": ["debug-test"]. Instead you should just be able to attach a listener to the correct port, kinda like this configuration:

        {
            "name": "Python: Attach Listen",
            "type": "debugpy",
            "request": "attach",
            "listen": { "host": "localhost", "port": 5678 },
            "justMyCode": true
        },

Give that a try and see if it would work to do the listen type on a attach request, and let me know how it goes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants