microsoft / vscode-python

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

Test panel incorrect for inherited, parametrized pytest tests #23558

Closed samamorgan closed 4 weeks ago

samamorgan commented 1 month ago

Type: Bug

Behaviour

When tests are discovered and displayed in the test panel, what pytest reports and what the test panel displays do not match. This also shows errors in the tests that do not actually occur during the test run.

Steps to reproduce:

  1. Create a base test class and inherit from that base:
class BaseTest:
    @pytest.fixture
    def the_fixture(self, data):
        return f"Data: {data}"

    def test_me(self, the_fixture):
        assert True

class TestOne(BaseTest):
    @pytest.fixture
    def the_fixture(self, data):
        return f"Data 1: {data}"

    @pytest.mark.parametrize("data", [1, 2, 3])
    def test_me(self, the_fixture):
        assert True

class TestTwo(BaseTest):
    @pytest.fixture
    def the_fixture(self, data):
        return f"Data 1: {data}"

    @pytest.mark.parametrize("data", [4, 5, 6])
    def test_me(self, the_fixture):
        assert True
  1. Refresh tests in the test panel
    • pytest collection will show the correct tests
      <Package foo>
      <Module tests.py>
      <Class TestOne>
      <Function test_me[1]>
      <Function test_me[2]>
      <Function test_me[3]>
      <Class TestTwo>
      <Function test_me[4]>
      <Function test_me[5]>
      <Function test_me[6]>
    • The test panel will show repeated tests for the inherited classes.
      foo
      └── tests.py
      ├── TestOne
      │   └── test_me
      │       ├── [1]
      │       ├── [2]
      │       ├── [3]
      │       ├── [4]
      │       ├── [5]
      │       └── [6]
      └── TestTwo
      └── test_me
          ├── [4]
          ├── [5]
          ├── [6]
          ├── [1]
          ├── [2]
          └── [3]

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` XXX ```

Extension version: 2024.6.0 VS Code version: Code 1.89.1 (Universal) (dc96b837cf6bb4af9cd736aa3af08cf8279f7685, 2024-05-07T05:14:24.611Z) OS version: Darwin arm64 23.5.0 Modes:

User Settings

``` Multiroot scenario, following user settings may not apply: languageServer: "Pylance" experiments • optInto: ["pythonTestAdapter"] ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |JavaScript Debugger|ms-vscode.js-debug|1.89.0| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.2| |Pylance|ms-python.vscode-pylance|2024.5.1| |Python|ms-python.python|2024.6.0| |Python Debugger|ms-python.debugpy|2024.6.0| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9|
System Info |Item|Value| |---|---| |CPUs|Apple M1 Max (10 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|2, 3, 2| |Memory (System)|32.00GB (2.44GB free)| |Process Argv|--crash-reporter-id 19c6bde3-9a40-4721-8b2c-60febe590630| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscorecescf:30445987 vscod805:30301674 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pythonmypyd1:30879173 pythoncet0:30885854 2e7ec940:31000449 pythontbext0:30879054 accentitlementsc:30995553 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 jchc7451:31067544 chatpanelc:31048052 dsvsc021:30996838 945dj816:31013170 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31061160 pythonprt:31056678 dwnewjupyter:31046869 26j00206:31048877 ```
eleanorjboyd commented 4 weeks ago

Hi! Can you try this on v2024.8.0 that was just released and let me know if that helps? We have just made some changes in this area on that release.

samamorgan commented 4 weeks ago

@eleanorjboyd That did it! Everything looks exactly as it should now! 🚀🎉