diff options
author | Thomas Grainger <tagrain@gmail.com> | 2024-12-18 10:12:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-18 10:12:24 (GMT) |
commit | bad3cdefa840ff099e5e08cf88dcf6dfed7d37b8 (patch) | |
tree | 08efcc0358f6952c191f0e3a441c14eafd03386d /Lib/test | |
parent | 2610bccfdf55bc6519808f8e1b5db2cfb03ae809 (diff) | |
download | cpython-bad3cdefa840ff099e5e08cf88dcf6dfed7d37b8.zip cpython-bad3cdefa840ff099e5e08cf88dcf6dfed7d37b8.tar.gz cpython-bad3cdefa840ff099e5e08cf88dcf6dfed7d37b8.tar.bz2 |
gh-126639: Add ResourceWarning to NamedTemporaryFile (#126677)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_tempfile.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 57e9bd2..7adc021 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -1112,11 +1112,14 @@ class TestNamedTemporaryFile(BaseTestCase): # Testing extreme case, where the file is not explicitly closed # f.close() return tmp_name - # Make sure that the garbage collector has finalized the file object. - gc.collect() dir = tempfile.mkdtemp() try: - tmp_name = my_func(dir) + with self.assertWarnsRegex( + expected_warning=ResourceWarning, + expected_regex=r"Implicitly cleaning up <_TemporaryFileWrapper file=.*>", + ): + tmp_name = my_func(dir) + support.gc_collect() self.assertFalse(os.path.exists(tmp_name), f"NamedTemporaryFile {tmp_name!r} " f"exists after finalizer ") |