【问题标题】:VS Code how to disable pydocstyle linting in testing files?VS Code 如何在测试文件中禁用 pydocstyle linting?
【发布时间】:2021-05-12 04:36:06
【问题描述】:

我目前正在做一个 python 项目,并决定安装 pydocstyle 来改善我的文档习惯。但是我不希望 pydocstyle 对我的测试文件进行 lint,并且想知道如何在 settings.json 中创建一个模式来实现这一点。谢谢

【问题讨论】:

    标签: python json visual-studio-code lint


    【解决方案1】:

    比如你的测试文件以test_为前缀,你可以在Settings.json中添加如下代码:

    "python.linting.ignorePatterns": [
        "test_*.py",
    ]
    

    然后您的测试文件将被排除在 linting 之外:

    【讨论】:

    • 感谢您的回复!这不会阻止 pylint 在测试文件上运行吗?
    • @creamycow。该设置适用于所有 linter,因此它也会阻止 pylint 运行测试文件。
    • 我仍在尝试在我的测试文件中使用 pydocstyle 和 flake8。我尝试做类似“python.linting.pydocstyle”的事情:false,[“test_*.py],但这没有用
    • 为了尽快重现您的问题,我还在我的项目中使用了 pydocstyle。我发布的设置可以应用于所有 linter。同样来自pydocstyle usage,默认为--match='(?!test_).*\.py',它匹配不以test_开头但以.py结尾的文件,但是当我在我的机器上测试时,它不起作用,所以我发布@987654329 @因为它也可以解决你的问题。
    【解决方案2】:

    终于找到了解决方案(但不要问我为什么会这样:)

    "python.linting.pydocstyleArgs": ["--match=^((?!test).)*$"],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-13
      • 2021-07-14
      • 2021-05-12
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 2017-10-02
      相关资源
      最近更新 更多