我已经使用pip安装了pytest。下面是示例代码
import pytest
def example():
assert 9 == 9我的settings.json文件如下所示
{
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
}在使用pytest filename.py命令时,我一直没有在终端上运行任何测试。
Python版本: 3.9.1;pytest版本: 6.2.2。
谁有什么想法?
更新:下面是Jason的答案。问题出在文件和方法的命名上。文件名需要以‘结尾’
_
test.py‘for vscode来运行以'test’开头所需的测试和函数
_
‘以便终端和vscode都能运行。
发布于 2021-02-16 20:30:38
尝试将文件重命名为"test
_
filename.py“和"test”的测试函数
_
示例“,这样它们就可以被pytest检测到。
https://docs.pytest.org/en/reorganize-docs/new-docs/user/naming
_
conventions.html
此外,用于调试运行测试能力的一个有用的pytest选项是"--collect-only“。它将尝试只查找测试,而不运行它们。
pytest --collect-onlyVSCode能够自行运行测试,而无需您在终端中执行它们。
https://code.visualstudio.com/docs/python/testing
https://stackoverflow.com/questions/66224250
复制相似问题