Skip to content

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

Closed

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

Activity

  1. eleanorjboyd commented on Jun 23, 2023

    @eleanorjboyd

    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!

  2. 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[/+] on Jun 23, 2023
  3. eleanorjboyd commented on Jun 26, 2023

    @eleanorjboyd

    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.

  4. prsmendonca commented on Jun 27, 2023

    @prsmendonca
    Author
  5. locked as resolved and limited conversation to collaborators on Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbugIssue identified by VS Code Team member as probable bugverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions