【问题标题】:different config value depending on running or debugging tests不同的配置值取决于运行或调试测试
【发布时间】:2017-11-16 10:59:19
【问题描述】:

在 VSCode 中,有一个功能可以让您Run tests and Debug tests,显示在测试函数的正上方。在我当前的项目中,我使用的是 py.test。我已经自定义了 py.test,所以它在两个线程中运行:

"python.unitTest.pyTestArgs": [
    "-n2"
],

这是我的问题:我能否将不同的参数传递给 py.test,具体取决于我点击的内容:运行测试调试测试

我想在运行时传递-q,这样我的输出就不会因为大量不需要的信息而变得臃肿,并在调试时传递-s --verbose-debug-log,因为我需要完整的堆栈跟踪。

【问题讨论】:

    标签: python visual-studio-code pytest


    【解决方案1】:

    好的,我无意中找到了我的问题的答案:

    您可以通过 launch.json 文件指定不同的启动选项,例如 chooseable here

    那里的条目会是这样的:

    (...)
        {
            "name": "Python: Debug with verbose log",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "${config:python.pythonPath}",
            "program": "",
            "cwd": "${workspaceRoot}",
            "env": {},
            "args": [
                "-s",
                "--verbose-debug-log"
            ],
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
    (...)
    

    【讨论】:

      猜你喜欢
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      • 1970-01-01
      • 2023-02-14
      • 2015-03-12
      • 1970-01-01
      相关资源
      最近更新 更多