簡體   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