1

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.

Rijul Gupta
  • 1,045
  • 13
  • 20

1 Answers1

0

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.

Rijul Gupta
  • 1,045
  • 13
  • 20
  • Unfortunately **this answer does not solve the problem**. My bet is that this **is an old VS Code bug**. Some information points to a bug that has been resolved. But, it doesn't seem to be a case. Too bad... – Eduardo Lucio Jun 21 '23 at 19:40