Skip to content

Support pytest-describe in testing rewrite #21705

Closed

Description

@QuentinFchx

Type: Bug

Behaviour

Expected vs. Actual

With the following dependencies:

"pytest==7.4.0"
"pytest-describe==2.1.0"

Considering the following test file:

# test_pytest_describe.py

def describe_A():
    def test_1():
        pass

    def test_2():
        pass


def describe_B():
    def test_1():
        pass

    def test_2():
        pass

When discovering tests (with the new adapter, "python.experiments.optInto": ["pythonTestAdapter"]), only the last describe block is registered, here describe_B.
By "registered", I mean :

  • displayed in the tests explorer
  • having a "run/debug test" quick action in the editor

Neither the describe_A block, nor its tests appear anywhere. FWIW, I tested with different test names, not conflicting between describe blocks (describe_B, test_3/test_4 instead of test_1/test_2), the issue sill occurs.

Screenshots Screenshot 2023-07-28 at 14 16 55 Screenshot 2023-07-28 at 14 16 42

In the Output for Python section below, I added an extract of the test collection output which includes the describe_A block. I assume it means the test collection works well but there is an issue down the line?

Steps to reproduce:

  1. See above

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.16
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

collected xx items

<Package test>
  [...]
  <Module test_pytest_describe.py>
    <DescribeBlock 'describe_A'>
      <Function test_1>
      <Function test_2>
    <DescribeBlock 'describe_B'>
      <Function test_1>
      <Function test_2>
  [...]

User Settings

Multiroot scenario, following user settings may not apply:

venvPath: "<placeholder>"

languageServer: "Pylance"

linting
• flake8Enabled: true
• mypyArgs: "<placeholder>"
• mypyEnabled: true

formatting
• provider: "black"
• blackArgs: "<placeholder>"

testing
• autoTestDiscoverOnSaveEnabled: false

experiments
• optInto: ["pythonTestAdapter"]

Extension version: 2023.12.0
VS Code version: Code 1.80.2 (Universal) (2ccd690cbff1569e4a83d7c43d45101f817401dc, 2023-07-27T21:05:41.366Z)
OS version: Darwin arm64 22.5.0
Modes:

System Info
Item Value
CPUs Apple M1 (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 3, 3, 2
Memory (System) 16.00GB (0.07GB free)
Process Argv
Screen Reader no
VM 0%

Activity

  1. added
    triage-needed
    on Jul 28, 2023
  2. changed the title [-]When using pytest-describe, test discovery only register the last `describe` block[/-] on Jul 28, 2023
  3. eleanorjboyd commented on Jul 31, 2023

    @eleanorjboyd

    will investigate, thank you for filing!

  4. eleanorjboyd commented on Jul 31, 2023

    @eleanorjboyd

    What args are required for pytest to recognize describe blocks? I am not seeing even pytest from the CLI recognize it with the sample code you provided. Thanks

  5. added
    info-needed
    on Jul 31, 2023
  6. QuentinFchx commented on Aug 2, 2023

    @QuentinFchx
    Author

    Unless I'm mistaken, no particular arguments are required.
    What can I do to help you reproduce, do you need a sample repository? (is there a sample repository with a boilerplate I can start from?)
    Otherwise I can try to give you more information about the issue, are there any flags I can use to debug directly in my IDE?

  7. removed
    info-needed
    on Aug 2, 2023
  8. eleanorjboyd commented on Aug 2, 2023

    @eleanorjboyd

    A sample repro would be extremely helpful! Just a folder with a python file (with the tests) then the .vscode folder (with the setttings.json) is what I should need. Thanks!

  9. added
    info-needed
    on Aug 2, 2023
  10. QuentinFchx commented on Aug 3, 2023

    @QuentinFchx
    Author

    I created https://github.com/QuentinFchx/pytestbug, can you tell me if that's working for you?

    The interesting part is that on this repository the issue still occurs, but now only the first describe block is taken into account (and not only the last).

  11. removed
    info-needed
    on Aug 3, 2023
  12. eleanorjboyd commented on Oct 4, 2023

    @eleanorjboyd

    Sorry for the delay on this- trying to determine prioritization with the rewrite. Is this a regression on the new rewrite? If so I can get to this more quickly, if it has never worked then I might have to mark this as a feature request. Thanks

  13. added
    info-needed
    on Oct 4, 2023
  14. 27 remaining items

  15. Nathaniel-Reeves commented on Feb 14, 2024

    @Nathaniel-Reeves

    +1

  16. dinzone commented on Feb 14, 2024

    @dinzone

    +1

  17. nkotzrenko commented on Feb 14, 2024

    @nkotzrenko

    +1

  18. alexkubica commented on Feb 15, 2024

    @alexkubica

    +1 🙏

  19. brettcannon commented on Feb 22, 2024

    @brettcannon
    Member

    Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.

    We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most.

  20. added
    community ask
    and removed
    needs community feedback
    on Feb 22, 2024
  21. eleanorjboyd commented on Dec 2, 2024

    @eleanorjboyd

    Verification Steps:

    1. create workspace, add this to a file labeled test_describe.py
    # test_pytest_describe.py
    
    def describe_A():
        def test_1():
            pass
    
        def test_2():
            pass
    
    
    def describe_B():
        def test_1():
            pass
    
        def test_2():
            pass
    
    1. install pytest and pytest-describe to your python environment
    2. configure tests using pytest
    3. ensure on test discovery that all these 4 tests are recognized as tests (with the run button next to them in the UI)
  22. added
    verification-needed
    on Dec 3, 2024
  23. DonJayamanne commented on Dec 4, 2024

    @DonJayamanne

    Eleanor Boyd (@eleanorjboyd) The steps provided by the user was already great enough, but no harm .
    Works perfectly fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingcommunity askfeature-requestneeds PRverification-neededverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions