[英]How to configure vscode in order to discover python unittests
I want to create automation tests for web application with Visual Studio code, Python and unittest.我想使用 Visual Studio 代码、Python 和单元测试为 Web 应用程序创建自动化测试。 However my Test Explorer fails to discover tests (no error appears it is just empty).
但是我的测试资源管理器未能发现测试(没有错误出现,它只是空的)。
Despite that i have needed extensions (Python, Test Explorer UI and Python Test Explorer), prepared settings.json and required methods' and classes' decoration, commands like run all tests or discover doesn't work out.尽管我需要扩展(Python、测试资源管理器 UI 和 Python 测试资源管理器)、准备好的 settings.json 和必需的方法和类的装饰,但运行所有测试或发现之类的命令不起作用。 However debugging whole file actually runs tests (i see output in terminal).
然而调试整个文件实际上运行测试(我在终端看到输出)。
CODE:代码:
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()
SETTINGS:设置:
{
"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"
}
List of things to consider:需要考虑的事项清单:
test_
.test_
开头命名您的测试文件。python -m unittest discover
in your project root directory.python -m unittest discover
。 If that does not find your tests, VSCode won't find them either.__init__.py
files)__init__.py
文件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.