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

testExceptionCleanupNames doesn't test anything? #90600

Closed
yellowdusk1590 mannequin opened this issue Jan 20, 2022 · 8 comments
Closed

testExceptionCleanupNames doesn't test anything? #90600

yellowdusk1590 mannequin opened this issue Jan 20, 2022 · 8 comments
Labels
3.11 only security fixes tests Tests in the Lib/test dir

Comments

@yellowdusk1590
Copy link
Mannequin

yellowdusk1590 mannequin commented Jan 20, 2022

BPO 46442
Nosy @ericvsmith, @JelleZijlstra, @miss-islington, @sobolevn, @yellowdusk1590
PRs
  • bpo-46442: improve testExceptionCleanupNames #30753
  • bpo-46442: improve testExceptionCleanupNames #30758
  • [3.10] bpo-46442: improve and rename testExceptionCleanupNames (GH-30758) #30778
  • [3.9] bpo-46442: improve and rename testExceptionCleanupNames (GH-30758) #30779
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-01-22.08:14:43.756>
    created_at = <Date 2022-01-20.00:33:05.618>
    labels = ['tests', '3.11']
    title = "testExceptionCleanupNames doesn't test anything?"
    updated_at = <Date 2022-01-22.08:14:43.755>
    user = 'https://github.com/yellowdusk1590'

    bugs.python.org fields:

    activity = <Date 2022-01-22.08:14:43.755>
    actor = 'eric.smith'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-22.08:14:43.756>
    closer = 'eric.smith'
    components = ['Tests']
    creation = <Date 2022-01-20.00:33:05.618>
    creator = 'yellowdusk1590'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46442
    keywords = ['patch']
    message_count = 8.0
    messages = ['410997', '411029', '411040', '411146', '411233', '411234', '411235', '411236']
    nosy_count = 5.0
    nosy_names = ['eric.smith', 'JelleZijlstra', 'miss-islington', 'sobolevn', 'yellowdusk1590']
    pr_nums = ['30753', '30758', '30778', '30779']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46442'
    versions = ['Python 3.11']

    @yellowdusk1590
    Copy link
    Mannequin Author

    yellowdusk1590 mannequin commented Jan 20, 2022

    testExceptionCleanupNames() is supposed to test that the local variable bound to the exception instance is only visible inside the except block, and tests that by checking whether the name is in locals(), but it actually deletes the name before that, so it appears it isn't testing what it's supposed to be testing.

            try:
                raise Exception()
            except Exception as e:
                self.assertTrue(e)
                del e
            self.assertNotIn('e', locals())
    

    @yellowdusk1590 yellowdusk1590 mannequin added 3.11 only security fixes tests Tests in the Lib/test dir labels Jan 20, 2022
    @ericvsmith
    Copy link
    Member

    I don't know for sure, but maybe it's trying to test "del" interacting with the fact that the "as e" part doesn't escape the "except" clause, unlike normal assignments:

    >>> try:
    ...     raise Exception
    ... except Exception as e:
    ...     print('exception raised')
    ...     foo = 1
    ...
    exception raised
    >>> foo
    1
    >>> e
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'e' is not defined

    @JelleZijlstra
    Copy link
    Member

    Perhaps it's testing that the implicit del doesn't blow up if the variable is already deleted.

    @yellowdusk1590
    Copy link
    Mannequin Author

    yellowdusk1590 mannequin commented Jan 21, 2022

    Great point, it's indeed a good thing to test. So I guess the test is just incomplete.

    @ericvsmith
    Copy link
    Member

    New changeset 82c5322 by Yellow Dusk in branch 'main':
    bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
    82c5322

    @miss-islington
    Copy link
    Contributor

    New changeset d4a9e34 by Miss Islington (bot) in branch '3.10':
    bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
    d4a9e34

    @miss-islington
    Copy link
    Contributor

    New changeset e064af5 by Miss Islington (bot) in branch '3.9':
    bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
    e064af5

    @ericvsmith
    Copy link
    Member

    Thanks, @yellowdusk1590!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants