diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-09-30 04:18:24 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-30 04:18:24 (GMT) |
| commit | ce0eaa67032389d64fd2d7fb510e34372082eef8 (patch) | |
| tree | ce2147a4f664006237454ceb956532bcca5a6bb3 | |
| parent | a1a4cfcc8ee0da9302c566031cb3425f3238dd29 (diff) | |
| download | cpython-ce0eaa67032389d64fd2d7fb510e34372082eef8.zip cpython-ce0eaa67032389d64fd2d7fb510e34372082eef8.tar.gz cpython-ce0eaa67032389d64fd2d7fb510e34372082eef8.tar.bz2 | |
[3.13] gh-124722: Fix leak in `test_detach_materialized_dict_no_memory` (GH-124769) (#124777)
gh-124722: Fix leak in `test_detach_materialized_dict_no_memory` (GH-124769)
(cherry picked from commit 6f4d64b048133c60d40705fb5ef776f78c7dd710)
Co-authored-by: sobolevn <mail@sobolevn.me>
| -rw-r--r-- | Lib/test/test_class.py | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 6002ea7..00c3225 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -1,7 +1,7 @@ "Test the functionality of Python classes implementing operators." import unittest -import test.support +from test.support import cpython_only, import_helper, script_helper testmeths = [ @@ -920,20 +920,36 @@ class TestInlineValues(unittest.TestCase): C.a = X() C.a = X() + @cpython_only def test_detach_materialized_dict_no_memory(self): - import _testcapi - class A: - def __init__(self): - self.a = 1 - self.b = 2 - a = A() - d = a.__dict__ - with test.support.catch_unraisable_exception() as ex: - _testcapi.set_nomemory(0, 1) - del a - self.assertEqual(ex.unraisable.exc_type, MemoryError) - with self.assertRaises(KeyError): - d["a"] + # Skip test if _testcapi is not available: + import_helper.import_module('_testcapi') + + code = """if 1: + import test.support + import _testcapi + + class A: + def __init__(self): + self.a = 1 + self.b = 2 + a = A() + d = a.__dict__ + with test.support.catch_unraisable_exception() as ex: + _testcapi.set_nomemory(0, 1) + del a + assert ex.unraisable.exc_type is MemoryError + try: + d["a"] + except KeyError: + pass + else: + assert False, "KeyError not raised" + """ + rc, out, err = script_helper.assert_python_ok("-c", code) + self.assertEqual(rc, 0) + self.assertFalse(out, msg=out.decode('utf-8')) + self.assertFalse(err, msg=err.decode('utf-8')) if __name__ == '__main__': unittest.main() |
