Repository navigation
Test Discovery Failed: Extension version v2023.11.11731012, pythonTestAdapter setting on #21476
Copy link
Copy link
Closed
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugverification-neededVerification of issue is requestedVerification of issue is requestedverifiedVerification succeededVerification succeeded
Milestone
Description
The Pre-release version v2023.11.11731012 of Microsoft's Python extension for Visual Studio Code fails to discover one of my tests.
Behaviour
The command
conda run -n my_env --no-capture-output python ~/.vscode-server-insiders/extensions/ms-python.python-2023.11.11731012/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.11.11731012/pythonFiles/unittestadapter/discovery.py --port 34713 --uuid 16c443af-8630-465d-8c14-8c5317ce917b --udiscovery -v -s ./tests -p *test*.pyResults in a Unittest test discovery error due to a module not being found.
Expected vs. Actual
In contrast, switching to release version v2023.10.1 of the same extension works without problems. It runs a different command, though:
conda run -n my_env --no-capture-output python ~/.vscode-server-insiders/extensions/ms-python.python-2023.10.1/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.10.1/pythonFiles/testing_tools/unittest_discovery.py ./tests *test*.pySteps to reproduce:
- Install Microsoft's Python extension, pre-release version v2023.11.11731012.
- Create a test in a directory that depends on a module with files outside that directory. E.g., "test" and "module" may be parallel directories, with a unit test in the directory "test" and "module" contains Python files and a file named "__init__.py".
- Configure tests.
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.8.16
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServersetting: Default
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2023-06-22 16:38:50.133 [info] Discover tests for workspace name: TNLGv4-Inference - uri: /home/paulo/repos/TNLGv4-Inference
2023-06-22 16:38:50.133 [info] Running discovery for unittest using the new test adapter.
2023-06-22 16:38:50.142 [info] > conda run -n my_env --no-capture-output python ~/.vscode-server-insiders/extensions/ms-python.python-2023.11.11731012/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.11.11731012/pythonFiles/printEnvVariables.py
2023-06-22 16:38:50.142 [info] shell: bash
2023-06-22 16:38:50.617 [info] Running unittests with arguments: /home/paulo/.vscode-server-insiders/extensions/ms-python.python-2023.11.11731012/pythonFiles/unittestadapter/discovery.py,--port,44497,--uuid,c99d8672-d60e-40e1-8e5a-cad8b005d80b,--udiscovery,-v,-s,./tests,-p,*test*.py
2023-06-22 16:38:50.617 [info] > conda run -n my_env --no-capture-output python ~/.vscode-server-insiders/extensions/ms-python.python-2023.11.11731012/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.11.11731012/pythonFiles/unittestadapter/discovery.py --port 44497 --uuid c99d8672-d60e-40e1-8e5a-cad8b005d80b --udiscovery -v -s ./tests -p *test*.py
2023-06-22 16:38:50.617 [info] cwd: .
2023-06-22 16:38:51.312 [info] Test server connected to a client.
2023-06-22 16:38:51.314 [info] Using result resolver for discovery
2023-06-22 16:38:51.314 [error] Unittest test discovery error
Failed to import test module: my_module_utils_test
Traceback (most recent call last):
File "/home/me/mambaforge/envs/my_env/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/home/me/mambaforge/envs/my_env/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/home/me/repos/my_repo/tests/my_module_utils_test.py", line 3, in <module>
from \
ModuleNotFoundError: No module named 'my_module'
User Settings
languageServer: "Pylance"
linting
• flake8Args: "<placeholder>"
• flake8Enabled: true
• pycodestyleEnabled: true
• pydocstyleEnabled: true
formatting
• autopep8Args: "<placeholder>"
• provider: "none"
testing
• unittestArgs: "<placeholder>"
• unittestEnabled: true
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugverification-neededVerification of issue is requestedVerification of issue is requestedverifiedVerification succeededVerification succeeded
Activity
eleanorjboyd commentedon Jun 23, 2023
Hi! Thank you for catching this! This is using our new test rewrite architecture and it seems to be missing the right path to find everything. I will investigate further and get back to you with any questions or a fix. For now, you can disable the new testing rewrite using
"python.experiments.optOutFrom": ["pythonTestAdapter"],. Thanks![-]Extension version v2023.11.11731012 fails to discover test found with v2023.10.1[/-][+]Test Discovery Failed: Extension version v2023.11.11731012, pythonTestAdapter setting on[/+]add to payload to allow error parsing on TS (#21483)
add cwd to python path during unittest sendCommand (#21490)
eleanorjboyd commentedon Jun 26, 2023
The reason for this is the cwd was not added to the PYTHONPATH when unittest discovery was run. This fix is now merged and will be out in insiders tomorrow. Verification steps are just the repro steps above- conda environment is not required to verify.
prsmendonca commentedon Jun 27, 2023