This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: testExceptionCleanupNames doesn't test anything?
Type: Stage: resolved
Components: Tests Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: JelleZijlstra, eric.smith, miss-islington, sobolevn, yellowdusk1590
Priority: normal Keywords: patch

Created on 2022-01-20 00:33 by yellowdusk1590, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30753 closed yellowdusk1590, 2022-01-21 16:57
PR 30758 merged yellowdusk1590, 2022-01-21 17:35
PR 30778 merged miss-islington, 2022-01-22 07:09
PR 30779 merged miss-islington, 2022-01-22 07:09
Messages (8)
msg410997 - (view) Author: Yellow Dusk (yellowdusk1590) * Date: 2022-01-20 00:33
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())
```
msg411029 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-20 15:41
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
msg411040 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-01-20 17:59
Perhaps it's testing that the implicit `del` doesn't blow up if the variable is already deleted.
msg411146 - (view) Author: Yellow Dusk (yellowdusk1590) * Date: 2022-01-21 16:45
Great point, it's indeed a good thing to test. So I guess the test is just incomplete.
msg411233 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-22 07:09
New changeset 82c53229e18f5853c82cb8ab6b9af1925a0e9e58 by Yellow Dusk in branch 'main':
bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
https://github.com/python/cpython/commit/82c53229e18f5853c82cb8ab6b9af1925a0e9e58
msg411234 - (view) Author: miss-islington (miss-islington) Date: 2022-01-22 07:34
New changeset d4a9e34401d519250d3b3744cd10394069f748c1 by Miss Islington (bot) in branch '3.10':
bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
https://github.com/python/cpython/commit/d4a9e34401d519250d3b3744cd10394069f748c1
msg411235 - (view) Author: miss-islington (miss-islington) Date: 2022-01-22 07:37
New changeset e064af564c8580285a76199229864ddfb1e50c0f by Miss Islington (bot) in branch '3.9':
bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
https://github.com/python/cpython/commit/e064af564c8580285a76199229864ddfb1e50c0f
msg411236 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-22 08:14
Thanks, @yellowdusk1590!
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90600
2022-01-22 08:14:43eric.smithsetstatus: open -> closed
resolution: fixed
messages: + msg411236

stage: patch review -> resolved
2022-01-22 07:37:40miss-islingtonsetmessages: + msg411235
2022-01-22 07:34:37miss-islingtonsetmessages: + msg411234
2022-01-22 07:09:52miss-islingtonsetpull_requests: + pull_request28964
2022-01-22 07:09:47miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28963
2022-01-22 07:09:45eric.smithsetmessages: + msg411233
2022-01-21 17:35:21yellowdusk1590setpull_requests: + pull_request28945
2022-01-21 16:57:50yellowdusk1590setkeywords: + patch
stage: patch review
pull_requests: + pull_request28940
2022-01-21 16:45:55yellowdusk1590setmessages: + msg411146
2022-01-20 17:59:32JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg411040
2022-01-20 17:38:08sobolevnsetnosy: + sobolevn
2022-01-20 15:41:17eric.smithsetnosy: + eric.smith
messages: + msg411029
2022-01-20 00:33:05yellowdusk1590create