[英]How do I select a sub-folder as a directory containing tests in Python extension for Visual studio code
I am using VScode with python code and I have a folder with sub-directories (2-levels deep) containing python tests.我正在将 VScode 与 python 代码一起使用,并且我有一个包含 python 测试的子目录(2 级深)的文件夹。
When I try "Python: Discover Tests" it asks for a test framework (selected pytest) and the directory in which tests exist.当我尝试“Python: Discover Tests”时,它要求提供一个测试框架(选定的 pytest)和测试所在的目录。 At this option, it shows only the top-level directories and does not allow to select a sub-directory.
在此选项中,它只显示顶级目录,不允许选择子目录。
I tried to type the directory path but it does not accept it.我试图输入目录路径,但它不接受。
Can someone please help on how to achieve this?有人可以帮助如何实现这一目标吗?
There are two options.有两种选择。 One is to leave the selection as-is and make sure your directories are packages by adding
__init__.py
files as appropriate.一种是保持选择
__init__.py
,并通过适当添加__init__.py
文件来确保您的目录是包。 The other is you can go into your workspace settings and adjust the "python.testing.pytestArgs"
setting as appropriate to point to your tests.另一个是您可以进入工作区设置并根据需要调整
"python.testing.pytestArgs"
设置以指向您的测试。
Try opening the "Output" log (Ctrl+Shift+U) and run "Python: Discover Tests".尝试打开“输出”日志 (Ctrl+Shift+U) 并运行“Python: Discover Tests”。 Alternatively, you may type
pytest --collect-only
into the console.或者,您可以在控制台中键入
pytest --collect-only
。 Maybe you are experiencing some errors with the tests themselves (such as importing errors).也许您在测试本身时遇到了一些错误(例如导入错误)。
Also, make sure to keep __init__.py
file in your "tests" folder.另外,请确保将
__init__.py
文件保留在“tests”文件夹中。
I am keeping the pytest "tests" folder within a subdirectory, and there are no issues with VS Code discovering the tests.我将 pytest“tests”文件夹保存在一个子目录中,并且 VS Code 发现测试没有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.