王锐
发布于 2024-10-24 / 27 阅读
0
0

如何使用vscode运行/调试Python程序

  1. 首先安装python扩展包插件,安装完毕后,创建以下两个文件 .vscode/tasks.json 以及 .vscode/launch.json。前者为运行python脚本,后者为调试python脚本,脚本内容如下:

// ./vscode/tasks.json 运行python脚本
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "testCaseWriter",
            "type": "shell",
            "command": "python",
            "args": ["${workspaceFolder}/testCaseWriter/main.py", "exl", 
                      "--ioP", "./data/intermediate/io.json",
                      "--mdcP", "./data/intermediate/mcdc.json",
                      "--tcP", "./data/intermediate/testcase.json",
                      "--fcP", "./input/function.txt",
                      "--tplP", "./data/template/ex_template.xlsx",
                      "--mP", "./data/template/TestCasePlayer.xlam",
                      "--outP", "./output"],
            "options": {
                "cwd": "D:\\test_target_project\\tool"
            },
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

上述文件配置完毕后,使用Ctrl + Alt + B 即可运行python脚本

  1. 调试配置文件

// ./vscode/launch.json 调试python脚本配置文件
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "testCaseWriter",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/testCaseWriter/main.py",
            "console": "integratedTerminal",
            "args": ["exl",
                      "--ioP", "./data/intermediate/io.json" ,
                      "--mdcP", "./data/intermediate/mcdc.json",
                      "--tcP", "./data/intermediate/testcase.json",
                      "--fcP", "./input/function.txt",
                      "--tplP", "./data/template/ex_template.xlsx",
                      "--mP", "./data/template/TestCasePlayer.xlam",
                      "--outP", "./output"],
            "cwd": "D:\\test_target_project\\tool"
        }
    ]
}

调试配置文件创建成功后,可以在左侧调试栏进行调试python脚本


评论