VSCode无法检测tests目录中的pytest测试用例,但终端运行pytest正常的问题排查求助
VSCode无法检测tests目录中的pytest测试用例,但终端运行pytest正常的问题排查求助
我正在做一个Python项目,用pytest来写测试,目前碰到个头疼的问题:终端里跑pytest完全正常,但VSCode的Testing面板一直是空的,还无限加载,根本检测不到tests目录里的测试用例。先跟大家说下我的项目情况和配置:
项目结构
.gitignore .pytest_cache/ .gitignore CACHEDIR.TAG README.md v/ cache/ nodeids stepwise .python-version .vscode/ settings.json hello.py pyproject.toml README.md tests/ __init__.py __pycache__/ test_test.py uv.lock
关键配置细节
- VSCode设置
我的.vscode/settings.json里已经配置了pytest相关的选项:
{ "python.testing.pytestArgs": [ "tests" ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true }
- 测试文件内容
tests/test_test.py里是个很简单的测试用例,确保逻辑没问题:
import pytest def test_example(): assert True # 后续会替换成实际测试逻辑
- 项目依赖配置
pyproject.toml里已经把pytest列为依赖了:
[project] name = "compass-extractor" version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.13" dependencies = [ "pytest>=8.3.5", ]
- 环境管理
我用uv来管理项目依赖,在终端里直接跑pytest命令,测试能正常执行,完全没问题。
遇到的问题
VSCode的Testing面板一直是空的,而且一直在加载,根本检测不到我写的测试用例,但是终端跑pytest一切正常。
我已经尝试过的排查步骤
- 确认pytest已经安装在当前项目的虚拟环境里了
- 检查了
python.testing.pytestEnabled确实设为true - 确认
python.testing.pytestArgs指向的是正确的tests目录
(附VSCode Testing面板状态:面板无任何测试用例显示,处于持续加载状态)
想请教下各位,这种情况可能是什么原因导致的?有没有什么解决办法?
备注:内容来源于stack exchange,提问作者MarcellGranat
相关产品推荐
相关产品推荐

