Prerequisites:
local host(win10)
- vscode
- vscode extension:
- remote-SSH
- remote-container
- docker
- docker desktop
remote host(Ubuntu)
- docker
Procedures
先在local host機(jī)器上安裝好vscode和各個extension
用remote-SSH extension ssh連接到remote host(Ubuntu)上的代碼文件夾, 比如
~/develop/test_project
在remote host(Ubuntu)上啟動container
-
打開vscode
docker extension
:
image.png 在彈出的container列表中選擇自己想要連接的container, 右鍵 ->
Attach to vscode
則會直接打開一個新的vscode, terminal會自動連接到container里
ctrl+P, 在頂部的欄里輸入
>Python: Configure Tests
在頂部的command欄里選擇pytest -> 文件夾
tests
-
此時 Testing 工具會刷新出pytest文件:
image.png 設(shè)置好pytest中的斷點
-
點擊瓢蟲小圖標(biāo)/右鍵debug test 就可以順利debug了:
image.png -
圖:
image.png -
如果需要測試django啟動, 直接在debug配置選擇django即可:
image.png