Skip to content

Breakpoints not hit in unit tests #392

Closed

Description

@bSolt

Issue Type: Bug

The python debugger used to work for debugging pytest unit tests, but now will not stop on breakpoints, exceptions, or when using "stopOnEntry"

I have the following entry in my launch.json:

{
    "name": "Python: Test",
    "type": "python",
    "request": "test",
    "console": "integratedTerminal",
    "envFile": "${workspaceFolder}/.env",
    "justMyCode": false,
    "stopOnEntry": false,
    "env": {
        "DEBUG": "true",
        "CF_DIET": "dev"
    }
}

And these settings:

 "python.testing.pytestArgs": [],
 "python.testing.unittestEnabled": false,
 "python.testing.nosetestsEnabled": false,
 "python.testing.pytestEnabled": true,

Extension version: 2020.8.105045
VS Code version: Code 1.48.2 (a0479759d6e9ea56afa657e454193f72aef85bd0, 2020-08-25T10:56:10.074Z)
OS version: Linux x64 3.10.0-1127.13.1.el7.x86_64

System Info
Item Value
CPUs Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz (4 x 2399)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: disabled_software
skia_renderer: disabled_off_ok
video_decode: unavailable_off
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled
Load (avg) 1, 1, 1
Memory (System) 15.51GB (0.58GB free)
Process Argv . --no-sandbox
Screen Reader no
VM 50%
DESKTOP_SESSION mate
XDG_CURRENT_DESKTOP MATE
XDG_SESSION_DESKTOP mate
XDG_SESSION_TYPE x11

Activity

  1. int19h commented on Aug 28, 2020

    @int19h
    Contributor

    Does it break if you use Pause on the debugger toolbar, or the built-in breakpoint() function?

    If so, is there anything unusual about the filenames that you see in the editor tabs and in the Call Stack pane when it breaks?

  2. bSolt commented on Sep 11, 2020

    @bSolt
    Author

    Sorry, missed the questions. I am able to pause it but only before my local code is run. Here's a screenshot of the call stack pane, which I don't think is unusual but not really sure what to look for.

    Screenshot at 2020-09-11 10-34-11

    I also figured out it does have something to do with this specific project, on another project I am able to hit by breakpoints. I am using the red circle breakpoints, I am unaware of how to use the built-in breakpoint function

    EDIT: I have now updated my email settings on this account so I will be notified to an email account I will check.

  3. karthiknadig commented on Sep 11, 2020

    @karthiknadig
    Member

    Braden Solt (@bSolt) Here is an example of calling breakpoint() function:

    def foo():
        breakpoint()
        print('here')        # Debugger stops here
    
    foo()
    

    This assumes you are using Python 3.7 or greater.

    For older versions of python, you can do this, and it is compatible with all versions of python (including 3.7 or greater).

    import debugpy
    def foo():
        debugpy.breakpoint()
        print('here')        # Debugger stops here
    
    foo()
    

    Note: you don;t have to install debugpy if you are running locally (on the same machine as the python-extension).

  4. bSolt commented on Sep 11, 2020

    @bSolt
    Author

    Braden Solt (@bSolt) Here is an example of calling breakpoint() function:

    def foo():
        breakpoint()
        print('here')        # Debugger stops here
    
    foo()
    

    This assumes you are using Python 3.7 or greater.

    For older versions of python, you can do this, and it is compatible with all versions of python (including 3.7 or greater).

    import debugpy
    def foo():
        debugpy.breakpoint()
        print('here')        # Debugger stops here
    
    foo()
    

    Note: you don;t have to install debugpy if you are running locally (on the same machine as the python-extension).

    Thanks for the quick tutorial, that's very straightforward. Running this particular project on 3.6.3 so I added

    import debugpy
    debugpy.breakpoint()

    But it doesn't stop either. How else can I help diagnose this?

  5. karthiknadig commented on Sep 11, 2020

    @karthiknadig
    Member

    I see. Try this:

    {
        "name": "Python: Test",
        "type": "python",
        "request": "test",
        "console": "integratedTerminal",
        "envFile": "${workspaceFolder}/.env",
        "justMyCode": false,
        "stopOnEntry": false,
        "env": {
            "DEBUG": "true",
            "CF_DIET": "dev"
        },
        "logToFile": true  // <--- this will enable logging.
    }

    You should be able to find logs in the extension folder: ~/.vscode/extensions/ms-python.python*. You should find files named debugpy-.log and pydevd.log. there will be multiple. Share them all.

  6. karthiknadig commented on Sep 11, 2020

    @karthiknadig
    Member

    Also, Share the list of extensions installed. Just do ls in the ~/.vscode/extensions folder.

  7. bSolt commented on Sep 11, 2020

    @bSolt
    Author

    List of extensions:

    $ ls ~/.vscode/extensions
    albymor.increment-selection-0.2.0
    alexkrechik.cucumberautocomplete-2.15.0
    davidanson.vscode-markdownlint-0.36.3
    eamodio.gitlens-10.2.2
    github.vscode-pull-request-github-0.15.0
    hediet.vscode-drawio-0.7.2
    ms-azuretools.vscode-docker-1.5.0
    ms-mssql.mssql-1.9.0
    ms-python.python-2020.8.106424
    ms-python.python-2020.8.108011
    mtxr.sqltools-0.23.0
    shaharkazaz.git-merger-0.4.1
    streetsidesoftware.code-spell-checker-1.9.0
    yzhang.markdown-all-in-one-3.3.0
    

    And here are the log files when I tried to run a single unit test with the breakpoint on (test_orchestration.py:48 is where I'm expecting it to stop):
    debugger.vscode_1e8eec5f-be62-4ccb-aa5e-0a008e75cd2e.log
    debugpy.adapter-10606.log
    debugpy.launcher-10669.log
    debugpy.pydevd.10675.log
    debugpy.server-10675.log

    EDIT: not sure why python extension shows up twice, but the log files came from the greater versioned one

  8. karthiknadig commented on Sep 11, 2020

    @karthiknadig
    Member

    Looks like it does not get to the breakpoint at all. Seems like you hit this error, before it gets to the breakpoint.

    AttributeError: <module 'lodges.jobs.task_classes.orchestration' from '/home/bsolt/repos/loadable-orchestration/lodges/jobs/task_classes/orchestration.py'> does not have the attribute 'get_job_by_id'
    

    You might have to use the Raised exception to catch these at the moment. uncaught is not enough because pytest catches all exceptions (so we can identify the above exception as uncaught).
    image

    Note: The debugger has a feature that detects these scenarios (user uncaught), but we have not enabled that yet.

  9. bSolt commented on Sep 11, 2020

    @bSolt
    Author

    Oh that does make sense... Well I'm glad that the "User Uncaught" feature would have alleviated my pain. The issue can probably be closed but I'll leave that up to you.

  10. karthiknadig commented on Sep 11, 2020

    @karthiknadig
    Member

    Closing this against user-unhandled, since this is closely related:
    #275
    #364

  11. bSolt commented on Sep 14, 2020

    @bSolt
    Author

    Karthik Nadig (@karthiknadig), can you take a look at another instance for me? I'm pretty sure this instance is a bug, because the execution fails a few lines into the test and I have put debug lines on each line of the test I am running, which seem to be ignored. Specifically, the line which pytest is highlighting here is test_flight_rule_check.py:22, which the execution should have been stopped on. The new log files are attached. Should I maybe open a new issue for this?

    debugpy.pydevd.7820.log
    debugpy.server-7820.log
    debugger.vscode_fd38b750-9887-4eb7-b2ab-30c875f8d888.log
    debugpy.adapter-7804.log
    debugpy.launcher-7814.log

  12. bSolt commented on Sep 14, 2020

    @bSolt
    Author

    In this case it seems like I am not about to pause using the toolbar.

  13. bSolt commented on Sep 14, 2020

    @bSolt
    Author

    Oh interesting, but when I try to use the inline breakpoint (debugpy.breakpoint()) it is able to pause execution!

  14. bSolt commented on Sep 14, 2020

    @bSolt
    Author

    Another note: once the inline breakpoint is caught, then you can continue as usual to hit subsequent breakpoints invoked via the UI without issue.

  15. karthiknadig commented on Sep 14, 2020

    @karthiknadig
    Member
  16. fabioz commented on Oct 9, 2020

    @fabioz
    Collaborator

    Braden Solt (@bSolt), I'm not exactly sure what's the issue... if you still can reproduce it, can you create a new issue providing some sample code to reproduce as well as the related logs?

  17. aminechm commented on Jun 7, 2025

    @aminechm

    what worked for me was clearing all .pyc and __pycache__ recursively using : https://gist.github.com/hbsdev/a17deea814bc10197285

    in both my local workspace and equivalent Docker container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions