Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Discovery Failed: Extension version v2023.11.11731012, pythonTestAdapter setting on #21476

Closed
prsmendonca opened this issue Jun 22, 2023 · 3 comments · Fixed by #21490
Closed
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@prsmendonca
Copy link

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*.py

Results 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*.py

Steps to reproduce:

  1. Install Microsoft's Python extension, pre-release version v2023.11.11731012.
  2. 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".
  3. 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.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, 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

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jun 22, 2023
@eleanorjboyd eleanorjboyd self-assigned this Jun 23, 2023
@eleanorjboyd
Copy link
Member

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!

@eleanorjboyd eleanorjboyd changed the title 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 Jun 23, 2023
eleanorjboyd added a commit that referenced this issue Jun 23, 2023
partial fix for #21476,
make sure error display correctly.


two part fix:
fix "errors" to "error" in unittest payload to align with naming
everywhere else
add "result" and "test" to payload in run and discovery respectively
even on error to havae resultResolver handle correctly.
@eleanorjboyd eleanorjboyd added bug Issue identified by VS Code Team member as probable bug area-testing labels Jun 26, 2023
@eleanorjboyd eleanorjboyd added this to the June 2023 milestone Jun 26, 2023
@eleanorjboyd eleanorjboyd removed the triage-needed Needs assignment to the proper sub-team label Jun 26, 2023
@eleanorjboyd
Copy link
Member

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.

@eleanorjboyd eleanorjboyd added the verification-needed Verification of issue is requested label Jun 26, 2023
@prsmendonca
Copy link
Author

prsmendonca commented Jun 27, 2023 via email

@luabud luabud added the verified Verification succeeded label Jun 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants