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

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

Closed
Carsopre opened this issue Feb 7, 2024 · 9 comments · Fixed by #23238
Closed
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@Carsopre
Copy link

Carsopre commented Feb 7, 2024

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 (ViewOutput, 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

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 7, 2024
@eleanorjboyd
Copy link
Member

will investigate- thanks!

@eleanorjboyd
Copy link
Member

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!

@eleanorjboyd eleanorjboyd added bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on and removed triage-needed Needs assignment to the proper sub-team labels Feb 7, 2024
@Wintreist
Copy link

Wintreist commented Feb 19, 2024

@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

@Carsopre
Copy link
Author

Carsopre commented Apr 9, 2024

Any update on this issue?

@eleanorjboyd
Copy link
Member

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

@eleanorjboyd
Copy link
Member

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!

@eleanorjboyd eleanorjboyd added the verification-needed Verification of issue is requested label Apr 19, 2024
@eleanorjboyd
Copy link
Member

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

@karthiknadig
Copy link
Member

Verified:
image

@karthiknadig karthiknadig added verified Verification succeeded and removed verification-needed Verification of issue is requested labels Apr 24, 2024
@rzhao271 rzhao271 added the verification-needed Verification of issue is requested label Apr 24, 2024
anthonykim1 pushed a commit to anthonykim1/vscode-python that referenced this issue May 10, 2024
@Carsopre
Copy link
Author

Thanks a lot @eleanorjboyd !!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2024
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 needs PR Ready to be worked on verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants