【问题标题】:VScode unittest configurationVScode 单元测试配置
【发布时间】:2020-07-09 13:31:43
【问题描述】:

我通常使用这个命令从我的项目根目录运行我的 python (3.6) 单元测试

python -m unittest discover -v -s . -p "test_*.py"

但是,我无法使用 vscode 进行设置。我的配置是

  "python.testing.unittestArgs": ["-v", "-s", ".", "-p", "test_*.py"],
  "python.testing.pytestEnabled": false,
  "python.testing.nosetestsEnabled": false,
  "python.testing.unittestEnabled": true

我收到了消息

No tests discovered, please check the configuration settings for the tests.

如何更正我的 vscode 设置以运行单元测试。

【问题讨论】:

  • 您在命令行和 VS Code 配置中使用不同的测试路径。对吗?
  • 糟糕,抱歉,我在 vscode 设置中尝试了各种路径。现已更正。
  • 查看Python Test Log 输出中显示的内容。您可以在View -> Output -> 中找到它,然后在控制台右侧选择输出类型。

标签: python unit-testing visual-studio-code


【解决方案1】:

您可以尝试将配置中的“.”更改为测试文件的直接父文件夹位置。

像这样:

"python.testing.unittestArgs": [
        "-v",
        "-s",
        "./A/a",
        "-p",
        "test_*.py"
    ],

指定测试文件的确切位置,它将被找到。

参考:This

【讨论】:

  • 我在项目级别,测试分布在各个模块中,所以我不能指定.以外的父文件夹。
【解决方案2】:

设置

 "python.testing.unittestArgs": ["-v", "-s", ".", "-p", "test*.py"],

工作。

【讨论】:

    猜你喜欢
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 2020-04-28
    相关资源
    最近更新 更多