[英]How to debug the current python test file with pytest in VS Code
[英]How to debug a file from current directory with Python in VS Code?
我可以看到這個問題已經被問過多次,但是,似乎沒有任何解決方案有效,迫使我尋求最新的修復。
問題
我在 VS 代碼中創建了一個具有以下目錄結構的工作區,
“work__assignments”是我在 VS 代碼中的主要工作區文件夾。 從這個主工作區,我 go 到作業文件夾(例如work__assignments > assignment__2 > modules )並處理相應的代碼。 但是,當我嘗試調試“ work__assignments > assignment__2 > modules ”中的代碼時,調試器從主工作區文件夾(即 work__assignments)加載,然后失敗,因為它無法在模塊文件夾“ work__assignments > assignment__2 > ”中找到其他模塊模塊”。
到目前為止,我已經嘗試了以下方法,
"cwd": "${fileDirname}"
,{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}"
}
"cwd": ""
,{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": ""
}
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"env": {
"PYTHONPATH": "${cwd}"
}
}
然而,這些方法都沒有奏效。 每次我調試代碼時,它都會啟動到工作區文件夾而不是代碼文件夾中。 我究竟做錯了什么?
在launch.json中配置以下cwd
之一:
"cwd": "./assignment__2"
"cwd": "${fileDirname}"
需要注意的是,您需要從運行和調試面板調試程序才能執行launch.json中的配置。
啟動.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
// "cwd": "./hello"
"cwd": "${fileDirname}"
}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.