繁体   English   中英

Python 在 Visual Studio Code 中测试多个文件

[英]Python tests in more than one file in Visual Studio Code

我正在使用unittest库使用 Visual Studio Code 为 Python/Django 应用程序运行一些测试。 他们工作得很好。 唯一的问题是我的测试位于多个文件中,我无法通过一次单击让 VS Code 运行所有测试,我必须单独运行每个文件。 我的结构是这样的:

/applications (folder)
   /folder1
      python_file_1.py
      python_file_2.py
      ...
      test_first.py
   /folder2
      python_file_3.py
      python_file_4.py
      ...
      test_second.py
      test_third.py

这会在测试资源管理器中生成此树:

在此处输入图像描述

文件test_*.py包含我的三组测试,但正如我所说,我一次只能运行它们。 如果我单击/applications级别的play按钮,VS Code 只会运行test_integration_comun.py文件中的测试。 有没有办法只需单击一下即可运行所有 3 个?

这是我配置unittest时 VS Code 添加的settings.json文件:

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

先谢谢您的帮助:)

要运行所有发现的测试,select 测试资源管理器顶部的播放按钮:

在此处输入图像描述

要运行一组特定的测试或单个测试,select 文件,class 或测试,然后 select 该项目右侧的播放按钮:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM