Skip to content

test_listcomps fails when run with -We #109182

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

Closed
AlexWaygood opened this issue Sep 9, 2023 · 2 comments · Fixed by #109271
Closed

test_listcomps fails when run with -We #109182

AlexWaygood opened this issue Sep 9, 2023 · 2 comments · Fixed by #109271
Assignees
Labels
3.12 only security fixes 3.13 bugs and security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@AlexWaygood
Copy link
Member

AlexWaygood commented Sep 9, 2023

Bug report

Bug description:

python -m test test_listcomps causes SyntaxWarnings to be emitted on main, and fails when run with -We:

Without -We:

0:00:00 Run tests sequentially
0:00:00 [1/1] test_listcomps
<string>:4: SyntaxWarning: 'set' object is not callable; perhaps you missed a comma?
<string>:6: SyntaxWarning: 'set' object is not callable; perhaps you missed a comma?
<string>:6: SyntaxWarning: 'set' object is not callable; perhaps you missed a comma?

== Tests result: SUCCESS ==

1 test OK.

Total duration: 230 ms
Total tests: run=49
Total test files: run=1/1
Result: SUCCESS

With -We:

======================================================================
ERROR: test_comp_in_try_finally (test.test_listcomps.ListComprehensionTest.test_comp_in_try_finally) (scope='module')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\alexw\coding\cpython\Lib\test\test_listcomps.py", line 122, in _check_in_scopes
    exec(newcode, newns)
  File "<string>", line 4
SyntaxError: 'set' object is not callable; perhaps you missed a comma?

======================================================================
ERROR: test_comp_in_try_finally (test.test_listcomps.ListComprehensionTest.test_comp_in_try_finally) (scope='class')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\alexw\coding\cpython\Lib\test\test_listcomps.py", line 122, in _check_in_scopes
    exec(newcode, newns)
  File "<string>", line 6
SyntaxError: 'set' object is not callable; perhaps you missed a comma?

======================================================================
ERROR: test_comp_in_try_finally (test.test_listcomps.ListComprehensionTest.test_comp_in_try_finally) (scope='function')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\alexw\coding\cpython\Lib\test\test_listcomps.py", line 122, in _check_in_scopes
    exec(newcode, newns)
  File "<string>", line 6
SyntaxError: 'set' object is not callable; perhaps you missed a comma?

----------------------------------------------------------------------

The problematic test is test_listcomps.ListComprehensionTest.test_comp_in_try_finally, which was added in d52c448 last week

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

@AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir 3.12 only security fixes 3.13 bugs and security fixes labels Sep 9, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Sep 9, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Sep 9, 2023
@serhiy-storchaka
Copy link
Member

It is not the only issue with these tests:

  1. test_comp_in_try_except only tests that the variable is finally restored after leaving the scope. It does not test that it is restored in the error handler.
  2. test_comp_in_try_except silences all exceptions by using a bare except. It can hide an error in the testing code.
  3. As well it does not ensure that an exception is not raised in one of cases.
  4. test_comp_in_try_finally emits a SyntaxWarning, as was originally reported.
  5. test_comp_in_try_finally does not check that the variable is restored in the finally block.
  6. finally block has two paths. test_comp_in_try_finally only tests one of them. The path without exception is not tested.
  7. test_comp_in_try_finally only tests the code in the function scope (because it wraps it in a function). module and class scopes are not tested.

I do not know about test_exception_in_post_comp_call because I do not know why it was added at first place. Does it test some case not covered by existing tests? Is there something special with this code that can make the variable not restoring immediately after successful evaluation of the comprehension?

@carljm
Copy link
Member

carljm commented Sep 11, 2023

@serhiy-storchaka thanks for reviewing and improving the tests! Will comment on your PR.

test_exception_in_post_comp_call is a regression test for a bug that I created in an early version of #108659 resulting in stack underflow when unwinding an exception raised inside a call occurring with the comprehension result still on the stack. It was surfaced by another test in the CPython test suite, but I wanted this case included in the listcomps tests.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 11, 2023
Yhg1s pushed a commit that referenced this issue Sep 12, 2023
…09271)

gh-109182: Fix and improve tests for gh-108654 (GH-109189)
(cherry picked from commit c0f488b)

Co-authored-by: Serhiy Storchaka <[email protected]>
@carljm carljm closed this as completed Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants