VSCode Python Testing `Test result not found for…` bug

huangapple go评论73阅读模式
英文:

VSCode Python Testing `Test result not found for...` bug

问题

以下是要翻译的内容:

在多项目(VSCode 称之为多根)的 Python 代码库中,当选择运行所有测试时,VSCode Python 插件在测试时失败,但运行单个文件夹或测试则通过。显然,这是一个奇怪的问题,因此我进一步进行了调查。

VSCode Python 插件在 "测试结果" 面板中的输出如下:

运行测试pytest):/home/workspace
使用参数运行测试--rootdir /home/workspace --override-ini junit_family=xunit1 --junit-xml=/tmp/tmp-289km5DwtjAXzkh.xml
当前工作目录/home/workspace
工作区目录/home/workspace
运行完成解析输出
未找到测试结果./my_awesome_dir/tests/my_awesome_module/my_awesome_test.py::TestAwesomeness::test_is_awesome[input_data0-AwesomeStuff]

这个问题在 vscode-python 仓库中曾经提到过,链接在这里:
https://github.com/microsoft/vscode-python/issues/18658

然而,尽管我找到了解决方法,但是 VSCode Python 仓库不允许在现有问题中添加更多评论,也不允许打开新问题,以便我可以在那里添加这些信息,这显然更合适。因此,我现在在这里添加这些信息,这可能是第二好的地方。

英文:

While working in a multi-project (VSCode would call it multi-root) python repository the VSCode python plugin for testing fails to run all the test when choosing to run all the tests, however running individual folders or tests passes. This is obviously a strange issue so I investigated this further.

The output of the vscode python plugin in the "Test Results" panel is as follows:

Running tests (pytest): /home/workspace
Running test with arguments: --rootdir /home/workspace --override-ini junit_family=xunit1 --junit-xml=/tmp/tmp-289km5DwtjAXzkh.xml
Current working directory: /home/workspace
Workspace directory: /home/workspace
Run completed, parsing output
Test result not found for: ./my_awesome_dir/tests/my_awesome_module/my_awesome_test.py::TestAwesomeness::test_is_awesome[input_data0-AwesomeStuff]

This issue has been mentioned before on the vscode-python repo here:
https://github.com/microsoft/vscode-python/issues/18658

However even though I found a solution for my problem the VSCode Python repository does not allow adding more comments to existing issues and neither do they allow opening new issues so that I can add this information over there which is much better suited. Therefore I am resorting to adding this information here which may be the second best place.

答案1

得分: 1

以下是您要翻译的内容:

基本上,问题发生在设置 settings.json 如下所示的情况下:

{
  "python.testing.pytestArgs": ["my_awesome_module"],
  "python.testing.pytestEnabled": true,
  "python.analysis.extraPaths": ["my_awesome_module"]
}

测试尝试从 /home/workspace 文件夹运行,而项目位于 /home/workspace/my_awesome_module

将 settings.json 更改为以下内容可以解决问题

{
  "python.testing.pytestEnabled": true,
  "python.testing.cwd": "${workspaceFolder}/my_awesome_module",
  "python.analysis.extraPaths": ["my_awesome_module"]
}

然后我们会得到以下输出:

运行测试 (pytest): /home/workspace/my_awesome_dir
使用参数运行测试: --rootdir /home/workspace --override-ini junit_family=xunit1 --junit-xml=/tmp/tmp-289hG1kDbHbe219.xml ./my_awesome_dir
当前工作目录: /home/workspace
工作区目录: /home/workspace
运行完成,解析输出
./my_awesome_dir/tests/my_awesome_module/my_awesome_test.py::TestAwesomeness::test_is_awesome[input_data0-AwesomeStuff] 通过

我怀疑使用 VSCode 工作区也可以解决这个问题,它会将存储库中的每个不同项目视为自己的根目录,但在我特定的情况下,设置工作区不是理想的,因此迄今为止唯一的解决方案是更改工作目录。

英文:

Essentially the issue happens when the settings.json has been set to the following:

{
  "python.testing.pytestArgs": ["my_awesome_module"],
  "python.testing.pytestEnabled": true,
  "python.analysis.extraPaths": ["my_awesome_module"],
}

The tests try to run from the /home/workspace folder, while the project lives in /home/workspace/my_awesome_module

Changing the settings.json to the following fixes the issue

{
  "python.testing.pytestEnabled": true,
  "python.testing.cwd": "${workspaceFolder}/my_awesome_module",
  "python.analysis.extraPaths": ["my_awesome_module"],
}

and we get the following output:

Running tests (pytest): /home/workspace/my_awesome_dir
Running test with arguments: --rootdir /home/workspace --override-ini junit_family=xunit1 --junit-xml=/tmp/tmp-289hG1kDbHbe219.xml ./my_awesome_dir
Current working directory: /home/workspace
Workspace directory: /home/workspace
Run completed, parsing output
./my_awesome_dir/tests/my_awesome_module/my_awesome_test.py::TestAwesomeness::test_is_awesome[input_data0-AwesomeStuff] Passed

I suspect the issue would also be resolved by using VSCode workspaces which would treat every different project in the repository as it's own root, however in my particular case setting up a workspace wasn't desirable and hence the only solution so far was changing the working directory.

huangapple
  • 本文由 发表于 2023年4月16日 23:26:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76028639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定