错误:在 VSCode (macOS)

问题描述

我试图通过单击编辑器字段中单元测试上方的 VSCode(或 Run Test)在 Debug Test 内运行单个单元测试,但我一直收到 {{1 }}:

ERROR: file not found

我怀疑这可能是由于当前工作目录, (即 ============================= test session starts ============================== platform darwin -- Python 3.8.8,pytest-4.6.11,py-1.10.0,pluggy-0.13.1 rootdir: <path_to_project_root>/module_1,inifile: /<path_to_project_root>/module_1/setup.cfg plugins: cov-2.12.1,mock-1.13.0,xdist-1.34.0,forked-1.3.0 collected 0 items - generated xml file: /var/folders/j9/lmgwz_dj4y97dx0zzf8kdgmc0000gn/T/tmp-1161ZMgD73kgVd4v.xml - ========================= no tests ran in 0.15 seconds ========================= ERROR: file not found: ./module_1/src/tests/pipelines/clean/test_cleaning.py::test_cleaning 中的 .)指向 ERROR: file not found: ./ 而不是 <path_to_project_root>/module_1,但如果我更改 <path_to_project_root> 中的 cwd 设置,VSCode 将停止发现我的测试。

我的目录树如下所示:

settings.json

以及 project_root/ ├─ module_1/ │ ├─ src/ │ │ ├─ tests/ │ ├─ setup.cfg ├─ module_2/ 中定义的一些(选定的)设置:

settings.json

我的 { "python.analysis.extraPaths": ["${workspaceFolder}/module_1/"],"python.autoComplete.extraPaths": ["${workspaceFolder}/module_1/"],"python.envFile": "${workspaceFolder}/.env","python.testing.autoTestdiscoverOnSaveEnabled": true,"python.languageServer": "Pylance","python.testing.cwd": "${workspaceFolder}/module_1","python.testing.pytestArgs": ["--rootdir","${workspaceFolder}/module_1"],"python.testing.nosetestsEnabled": false,"python.testing.unittestEnabled": false,"python.testing.pytestEnabled": true } 文件

.env

我的问题本质上是:在这样的(单一)存储库中,在 VSCode 中运行单个单元测试时,如何解决 PYTHONPATH="<path_to_project_root>/module_1/src/" 错误

附带/辅助问题:

  • 如何将 ERROR: file not found 当前工作目录设置为 pytest 但仍然让 VSCode 发现我的测试位于 <path_to_project_root> 中?
  • 或者,如何让 <path_to_project_root>/module_1/src/ 保持为 cwd,但在查找测试时告诉 VSCode 不要添加前缀 <path_to_project_root>/module_1
  • /module_1/ 应该如何允许在 monorepo 内无缝使用 settings.json

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)