23

How to enter into imported package while debugging in VS code

As an example:

import os
import mdfreader
k123 = mdfreader.mdf("Test.mf4")

How to enter into the mdf function in the imported package

8 Answers 8

38

In your launch.json add the "justMyCode": false setting. That will allow you to step into third-party code.

Sign up to request clarification or add additional context in comments.

1 Comment

It looks like this option was renamed to "justMyCode": false github.com/microsoft/vscode-python/issues/…
4

@Brett's answer is correct. However, when trying to debug 3rd party package while running unit tests (as opposed to running a predefined launch configuration) you need to create a separate configuration entry in the launch.json:

{
  "name": "Debug Unit Test",
  "type": "python",
  "request": "test",
  "justMyCode": false,
}

Comments

2

It looks like now you need to add "debugpy.debugJustMyCode": false, to your user settings.json file in vscode. Changing the launch.json didn't work for me.

Comments

0

Use Alt and left mouse and click the function you want to explore.
And you can edit it in keybindings.json by Ctrl+K Ctrl+S.

Comments

0

While debugging generaly you can step into to inspect the inner function/code.

1 Comment

This would be more helpful if you provided an example or linked to a tutorial or something. For example, I'm trying to debug a 3rd party module to see why it is breaking for my use case, and I need to see how values get passed around in the package to see if what I provide at the highest level ever makes it to the function imported from a utilities file into the main module.
0

@Tomasz's answer still works, though the editor would warn you that "test" is not an allowed value for the "request" property of launch configs configurations.

According to the discussion in https://github.com/microsoft/vscode-python/issues/15790 and the document in https://code.visualstudio.com/docs/python/testing#_debug-tests, I think now the recommended way to debug 3rd-party python package when running tests is:

{
  "name": "Python: Debug Tests",
  "type": "python",
  "request": "launch",
  "program": "${file}",
  "purpose": ["debug-test"],
  "console": "integratedTerminal",
  "justMyCode": false
}

Comments

0

two lines should be set in project settings.

"justMyCode": false, "purpose":["debug-in-terminal"]

eg. launch.json:
"configurations": [
  {
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "purpose":["debug-in-terminal"],
    "justMyCode": false,
    "args": ["-arg1", "-arg1"],
    "env": {"env1": "val1", "env2": "val2"}
  }
]

Comments

0

A solution, from here:

{
  "name": "Python: Debug Tests",
  "type": "debugpy",
  "request": "launch",
  "program": "${file}",
  "purpose": ["debug-test"],
  "console": "integratedTerminal",
  "justMyCode": false
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.