我不知道这是否是由于最近的更新所致,但我看到我的 Python 测试出现了两次,当我处于测试调试模式时,它也运行了两次。我该如何解决这个问题?我刚刚创建了一个空项目,但遇到了同样的问题。
重现步骤:
python -m venv .venv
(创建虚拟环境)
source ./.venv/bin/activate
(激活virtualenv)
pip install pytest==8.3.3
在 VSCode 上选择 Python 解释器作为 virtualenv 。
mkdir server server/tests
基本测试文件
# server/tests/test_storage.py
import pytest
class TestStorage:
def test(self):
pass
Settings.json(我尝试了目录的不同变体)
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
VSCode 版本:1.94.0(通用)
事实证明,这是由于启用了 Python 和 Python Test Explorer for Visual Studio Code 扩展,它们都具有测试功能。禁用后者解决了问题。