LoginSignup
4
6

More than 1 year has passed since last update.

Python+VSCode+Unitテスト+Debugするときにライブラリモジュールの中までステップインする設定

Last updated at Posted at 2021-03-12

経緯

PythonのUnittestをVSCodeでDebug実行した際、importした外部のライブラリモジュールまではステップインできませんでした。
その際、DEBUG CONSOLEには下記のメッセージが表示されます。

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).

justMyCode: false 設定は知っています。Debug実行時に外部のライブラリモジュールにステップインするための設定です。
ですが、VSCodeのテスト機能の場合はどう記述するのでしょうか?

(参考)Debug Test起動スイッチたち

image.png

(2021年3月時点の)答え

2022年10月時点ではこの記述でも動作しますが、requestキーに対する値は launch または attach にするようシンタックス警告されます。
オススメ設定を次のセクションに記載します

launch.json への記述で、"request": "test""justMyCode": false とします。
これで、テストをデバッグ実行した際に適用されます。

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Unittest",
            "type": "python",
            "request": "test",
            "justMyCode": false
        },
# 以下省略

2022年10月時点の記述方法

以前との違い

  • request: test→launch
  • purpose: 新規 ["debug-test"]

参考: https://code.visualstudio.com/docs/python/debugging#_purpose

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Debug Test",
            "type": "python",
            "request": "launch",
            "purpose": ["debug-test"],
            "console": "integratedTerminal",
            "justMyCode": false
        },
# 以下省略
4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6