[英]How to configure vscode in order to discover python unittests
我想使用 Visual Studio 代碼、Python 和單元測試為 Web 應用程序創建自動化測試。 但是我的測試資源管理器未能發現測試(沒有錯誤出現,它只是空的)。
盡管我需要擴展(Python、測試資源管理器 UI 和 Python 測試資源管理器)、准備好的 settings.json 和必需的方法和類的裝飾,但運行所有測試或發現之類的命令不起作用。 然而調試整個文件實際上運行測試(我在終端看到輸出)。
代碼:
import unittest
class testClass(unittest.TestCase):
def test_method(self):
self.assertEqual(1, 1)
def test_method2(self):
self.assertEqual(1, 2)
if __name__ == '__main__':
unittest.main()
設置:
{
"testExplorer.showOnRun": true,
"python.testing.unittestEnabled": true,
"python.testing.pyTestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.pythonPath": "C:\\Users\\Cezary\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe"
}
需要考慮的事項清單:
test_
開頭命名您的測試文件。python -m unittest discover
。 如果沒有找到您的測試,VSCode 也不會找到它們。__init__.py
文件)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.