Skip to content

Pytest parametrized tests in a class displayed under class node instead of test node #22870

Closed

Description

Type: Bug

Behaviour

Expected vs. Actual

On previous VSCode versions the TestExplorer would display the parametrized tests hanging from the test name's node regardless of this test being part of a test class or not. Since, at least, 2023 June release this is no longer the case and all parametrized tests will be directly appended to the class's tests.

(Perhaps related or consequence of the fix from #21541)

Steps to reproduce:

  1. Create a python (discoverable) test file test_dummy.py.
  2. Add the following code representing a loose test method and a wrapped one (both doing exactly the same):
import pytest

@pytest.mark.parametrize(
    "a", [pytest.param(0, id="Fist case for loose test"), pytest.param(1)]
)
def test_simple_dummy(a: int):
    assert a == 0

class TestWrapper:
    @pytest.mark.parametrize(
        "a", [pytest.param(0, id="First case for wrapped test"), pytest.param(1)]
    )
    def test_dummy(self, a: int):
        assert a == 0
  1. The test cases for the "loose" test method (test_simple_dummy) will be correctly visualized in the test explorer, whilst the cases in the wrapped test class will be appended directly to the TestWrapper node.
    Result:
    image
  2. Expected behavior: the parametrized cases are represented always as individual nodes hanging from their parent test method regardless of the test method being part of a class or not.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.11
  • 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)

XXX

User Settings


envFile: "<placeholder>"

languageServer: "Pylance"

testing
• cwd: "<placeholder>"
• pytestArgs: "<placeholder>"
• pytestEnabled: true

experiments
• optInto: ["pythonTestAdapter"]

Extension version: 2024.0.1
VS Code version: Code 1.86.0 (05047486b6df5eb8d44b2ecd70ea3bdf775fd937, 2024-01-31T10:28:19.990Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz (12 x 2592)
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
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.78GB (20.49GB free)
Process Argv --crash-reporter-id 94c5d108-18e9-4299-92c6-89e7bb27f0f0
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:30899288
vscaat:30438848
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30951796
pythongtdpath:30769146
welcomedialogc:30910334
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
pythontbext0:30879054
accentitlementst:30887150
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
dsvsc019bcf:30953938
8082a590:30958339
3ef8e399:30949928

Activity

  1. added
    triage-needed
    on Feb 7, 2024
  2. eleanorjboyd commented on Feb 7, 2024

    @eleanorjboyd

    will investigate- thanks!

  3. eleanorjboyd commented on Feb 7, 2024

    @eleanorjboyd

    verified I can see this issue too and it is a bug. Next step will be sending a PR for the fix. Thanks for the heads up here on this issue!

  4. added
    bug
    needs PR
    and removed
    triage-needed
    on Feb 7, 2024
  5. Wintreist commented on Feb 19, 2024

    @Wintreist

    Eleanor Boyd (@eleanorjboyd) Please write here when it will be possible to download a pre-release with a fix for this problem, or somehow let us know that the problem has been fixed

  6. Carsopre commented on Apr 9, 2024

    @Carsopre
    Author

    Any update on this issue?

  7. eleanorjboyd commented on Apr 15, 2024

    @eleanorjboyd

    Hi! I am back from vacation and circling back to this issue now- thanks

  8. eleanorjboyd commented on Apr 18, 2024

    @eleanorjboyd

    Hello! I have put in a fix for this issue and it should now be working! If you could try it on the newest version of the python extension nightly pre-release that would be great so we know if it works!

    Happy coding!

  9. added
    verification-needed
    on Apr 19, 2024
  10. eleanorjboyd commented on Apr 23, 2024

    @eleanorjboyd

    verification steps:

    1. create python venv
    2. install pytest using "python -m pip install pytest"
    3. use the code below
    4. open the test explorer, select pytest then root "."
    5. check to make sure the nesting is as so file>TestWrapper>test_dummy>First case for wrapped test
    import pytest
    
    @pytest.mark.parametrize(
        "a", [pytest.param(0, id="Fist case for loose test"), pytest.param(1)]
    )
    def test_simple_dummy(a: int):
        assert a == 0
    
    class TestWrapper:
        @pytest.mark.parametrize(
            "a", [pytest.param(0, id="First case for wrapped test"), pytest.param(1)]
        )
        def test_dummy(self, a: int):
            assert a == 0
    
  11. karthiknadig commented on Apr 24, 2024

    @karthiknadig
    Member

    Verified:
    image

  12. added
    verified
    and removed
    verification-needed
    on Apr 24, 2024
  13. added
    verification-needed
    on Apr 24, 2024
  14. Carsopre commented on May 13, 2024

    @Carsopre
    Author
  15. locked as resolved and limited conversation to collaborators on Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbugneeds PRverification-neededverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions