microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.33k stars 1.19k forks source link

Tests are missing depending on Python interpreter #24368

Open bfrv opened 3 weeks ago

bfrv commented 3 weeks ago

Type: Bug

Behaviour

Depending on the selected Python Interpreter, some tests are missing from the Test Explorer.

Steps to reproduce:

  1. Start a Python project
  2. Add tests (under /tests/ and /tests/subfolder)
    
    import pytest

def test_method() -> None: pass

@pytest.mark.parametrize( "arg", (1, 2, 3) ) def test_parametrized_method(arg: int) -> None: pass

class TestClass: def test_class_method(self) -> None: pass

@pytest.mark.parametrize(
    "arg",
    (1, 2, 3)
)
async def test_parametrized_class_method(self, arg: int) -> None:
    pass
3. Open the VSCode Test Explorer
4. Switch between Python interpreters

### Example 1: Poetry (3.12.3):
![Image](https://github.com/user-attachments/assets/71452e4d-a0f3-40d5-9f81-32c24638d345)
Note that all tests are showing as expected

### Example 2: Conda (3.12.4):
![Image](https://github.com/user-attachments/assets/20900006-0902-4df2-b816-f6af6accce1c)
Note that:
* `test_method` tests are missing
* `test_parametrized_method` tests are missing
* `test_parametrized_class_method` tests are missing
* The `TestClass` nodes are missing (`test_class_method` tests are displayed as children of the `test_test.py` nodes)

<details>

<summary>The Python Output panel does show that pytest picks up all tests</summary>

<p>

2024-10-31 13:04:12.320 [info] ============================= test session starts ============================== platform linux -- Python 3.12.4, pytest-6.2.5, py-1.11.0, pluggy-1.5.0

2024-10-31 13:04:12.323 [info] rootdir: /home/bart/temp/pytest plugins: asyncio-0.15.1, flaky-3.7.0, mypy-testing-0.0.12, cov-5.0.0, mock-3.14.0, datadir-1.5.0, anyio-3.7.1

2024-10-31 13:04:12.332 [info] collected 16 items

2024-10-31 13:04:12.332 [info] 2024-10-31 13:04:12.332 [info] ---: test_parametrized_method 2024-10-31 13:04:12.332 [info] ---: test_parametrized_method ---: test_parametrized_method 2024-10-31 13:04:12.333 [info] ---: test_parametrized_class_method 2024-10-31 13:04:12.333 [info] ---: test_parametrized_class_method ---: test_parametrized_class_method 2024-10-31 13:04:12.333 [info] ---: test_parametrized_method 2024-10-31 13:04:12.333 [info] ---: test_parametrized_method ---: test_parametrized_method 2024-10-31 13:04:12.333 [info] ---: test_parametrized_class_method 2024-10-31 13:04:12.333 [info] ---: test_parametrized_class_method ---: test_parametrized_class_method 2024-10-31 13:04:12.334 [info] ========================= 16 tests collected in 0.01s ========================== << # Diagnostic data Extension version: 2024.16.1 VS Code version: Code 1.94.2 (384ff7382de624fb94dbaf6da11977bba1ecd427, 2024-10-09T16:08:44.566Z) OS version: Linux x64 6.8.0-47-generic snap Modes: - Python version (& distribution if applicable, e.g. Anaconda): 3.12.3 - Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Poetry - Value of the `python.languageServer` setting: Default
User Settings

``` languageServer: "Pylance" testing • pytestEnabled: true ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |autoDocstring - Python Docstring Generator|njpwerner.autodocstring|0.6.1| |Black Formatter|ms-python.black-formatter|2024.4.0| |Dev Containers|ms-vscode-remote.remote-containers|0.389.0| |Docker|ms-azuretools.vscode-docker|1.29.3| |Even Better TOML|tamasfe.even-better-toml|0.19.2| |GitLab Workflow|GitLab.gitlab-workflow|5.17.0| |GitLens — Git supercharged|eamodio.gitlens|15.6.2| |Insert Unicode|brunnerh.insert-unicode|0.15.1| |JavaScript Debugger|ms-vscode.js-debug|1.94.0| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.3| |Kubernetes|ms-kubernetes-tools.vscode-kubernetes-tools|1.3.18| |Pylance|ms-python.vscode-pylance|2024.10.1| |Python|ms-python.python|2024.16.1| |Python Debugger|ms-python.debugpy|2024.12.0| |Python Environment Manager|donjayamanne.python-environment-manager|1.2.4| |Remote - SSH|ms-vscode-remote.remote-ssh|0.115.0| |Remote - SSH: Editing Configuration Files|ms-vscode-remote.remote-ssh-edit|0.87.0| |Remote - Tunnels|ms-vscode.remote-server|1.5.2| |Remote Development|ms-vscode-remote.vscode-remote-extensionpack|0.26.0| |Remote Explorer|ms-vscode.remote-explorer|0.4.3| |rust-analyzer|rust-lang.rust-analyzer|0.3.2162| |SVG|jock.svg|1.5.4| |Swagger Viewer|Arjun.swagger-viewer|3.1.2| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.10| |Tasks Shell Input|augustocdias.tasks-shell-input|1.12.4| |Vue - Official|Vue.volar|2.1.10| |WSL|ms-vscode-remote.remote-wsl|0.88.5| |YAML|redhat.vscode-yaml|1.15.0|
System Info |Item|Value| |---|---| |CPUs|13th Gen Intel(R) Core(TM) i7-13700H (20 x 2300)| |GPU Status|2d_canvas: unavailable_software
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
opengl: disabled_off
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software
webgpu: disabled_off
webnn: disabled_off| |Load (avg)|3, 3, 3| |Memory (System)|31.02GB (7.07GB free)| |Process Argv|--no-sandbox --force-user-env --crash-reporter-id 5610811c-82ac-49b0-bc5b-c52b6546f4c0| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|ubuntu| |XDG_CURRENT_DESKTOP|Unity| |XDG_SESSION_DESKTOP|ubuntu| |XDG_SESSION_TYPE|x11|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805:30301674 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyonecf:30548226 962ge761:30959799 pythongtdpath:30769146 pythonnoceb:30805159 asynctok:30898717 pythonmypyd1:30879173 2e7ec940:31000449 pythontbext0:30879054 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 dsvsc021:30996838 945dj816:31013170 dvdeprecation:31068756 dwnewjupyter:31046869 2f103344:31071589 impr_priority:31102340 nativerepl1:31139838 refactort:31108082 pythonrstrctxt:31112756 wkspc-onlycs-t:31132770 nativeloc2:31134642 wkspc-ranged-t:31151552 cf971741:31144450 iacca2:31156134 notype1cf:31157160 5fd0e150:31155592 dwcopilot:31170013 ```
eleanorjboyd commented 3 weeks ago

will try this- can you confirm that pytest is installed in both environments and there are no difference in pytest plugins?