Skip to content

Nested test classes not displaying pytest #22520

Closed

Description

Type: Bug

Create a pytest structure like this:

class TestMyClass
    def test_mytest

    class TestSubCategory
        def test_another_test

Extension version: 2023.20.0
VS Code version: Code 1.84.2 (1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, 2023-11-09T10:51:52.184Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Remote OS version: Linux x64 6.2.0-1016-azure

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 x 2808)
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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.89GB (6.27GB free)
Process Argv --crash-reporter-id ae591a24-d374-4309-8087-11db7f271645
Screen Reader no
VM 0%
Item Value
Remote Codespaces: orange giggle
OS Linux x64 6.2.0-1016-azure
CPUs AMD EPYC 7763 64-Core Processor (2 x 2432)
Memory (System) 7.74GB (5.29GB free)
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscorecescf:30445987
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263:30880072
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
2e4cg342:30602488
89544117:30613380
2i9eh265:30646982
showlangstatbar:30737416
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
synctok:30869157
dsvsc013:30795093
dsvsc014:30804076
dsvsc015:30845448
pythontestfixtcf:30871695
pythonregdiag2:30871582
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:30885898
pythontbext0:30879054
accentitlementsc:30887149
dsvsc016:30886110
dsvsc017cf:30886113
dsvsc018:30886114
aa_t_chat:30882232

test_bug

You can easily reproduce this bug in a codespace for megamock

https://github.com/JamesHutchison/megamock

Logs indicate pytest is correctly finding the tests so it appears this is a bug in how the results are interpreted

2023-11-23 18:06:55.946 [info]       <Function test_allows_for_setting_different_type>
      <Function test_assert_called_once_with>
      <Function test_return_value_equality_set_in_params>
      <Function test_return_value_equality_set_via_attribute>
      <Function test_meganame>
      <Function test_nested_assignment>

2023-11-23 18:06:55.946 [info]       <Class TestGenerateMockName>
        <Function test_name_of_class>
        <Function test_name_of_method>
        <Function test_name_of_mock_with_no_spec>
        <Function test_child_of_mock_with_no_spec>

Activity

  1. added
    triage-needed
    on Nov 23, 2023
  2. changed the title [-]Mid-level tests not displayed / counted[/-] on Nov 23, 2023
  3. eleanorjboyd commented on Nov 27, 2023

    @eleanorjboyd

    I honestly didn't know you could nest classes like this! Do you think it is necessary to handle an unknown number of nested classes or is going 2 levels down sufficient? Will investigate a fix. Thanks

  4. added
    info-needed
    on Nov 27, 2023
  5. JamesHutchison commented on Nov 27, 2023

    @JamesHutchison
    Author

    I would support up to at least 3, with supporting more (or an arbitrary amount) being better. I haven't needed to write 3 levels deep, but nested classes are an organization thing and it seems plausible there's some edge cases in some repos where it goes beyond 2. Like a user might do this:

    class TestMyClass:
        def test_something_integration(self):
            ...
        class TestAMethod:
            def test_ungrouped_test(self):
                ...
            class TestGroupA:
            
            class TestGroupB:
            
  6. removed
    info-needed
    on Nov 27, 2023
  7. added
    bug
    needs PR
    and removed
    triage-needed
    on Nov 27, 2023
  8. eleanorjboyd commented on Nov 27, 2023

    @eleanorjboyd

    sweet thanks! Added this as a bug but no promises on a timeline for when I can work on this.

  9. changed the title [-]Mid-level tests not displayed / counted (pytest)[/-] on Dec 5, 2023
  10. removed
    needs PR
    on Dec 19, 2023
  11. locked as resolved and limited conversation to collaborators on Jan 19, 2024
  12. added
    verification-needed
    on Jan 22, 2024
  13. added this to the milestone on Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbugverification-neededverified

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions