Skip to content

Commit d2e2a11

Browse files
authored
Add a non-issue test case (closure)
1 parent fb29db1 commit d2e2a11

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/datetimetester.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7331,6 +7331,24 @@ def gen():
73317331
res = script_helper.assert_python_ok('-X', 'showrefcount', '-c', script)
73327332
self.assertIn(b'[0 refs, 0 blocks]', res.err)
73337333

7334+
with self.subTest('With closure'):
7335+
# Finalization does not happen when a generator is nested
7336+
script = textwrap.dedent("""
7337+
def no_issue():
7338+
def gen():
7339+
try:
7340+
yield
7341+
finally:
7342+
assert sys.modules
7343+
import sys
7344+
it = gen()
7345+
next(it)
7346+
7347+
exec(no_issue.__code__)
7348+
""")
7349+
res = script_helper.assert_python_ok('-c', script)
7350+
self.assertFalse(res.err)
7351+
73347352

73357353
def load_tests(loader, standard_tests, pattern):
73367354
standard_tests.addTest(ZoneInfoCompleteTest())

0 commit comments

Comments
 (0)