Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Open
Description
Consider this repro:
draft @ cat zip-tb.txt>>> import zipfile>>> import io>>> zf = zipfile.ZipFile(io.BytesIO(), 'w')>>> zf.foo # doctest: +ELLIPSISTraceback (most recent call last):...AttributeError: ... draft @ py -3.12 -m doctest zip-tb.txtException ignored in: <function ZipFile.__del__ at 0x100f36b60>Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/zipfile/__init__.py", line 1916, in __del__ self.close() File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/zipfile/__init__.py", line 1933, in close self.fp.seek(self.start_dir)ValueError: I/O operation on closed file.
The test runs fine, but triggers aValueError
atexit
.
The issue only arises if the last expression in the doctest triggered a traceback and the zipfile was present in the traceback. Changingzf.foo
toio.foo
or adding>>> pass
bypasses the error.
I suspect there's a flaw in doctest that leaves resources unclosed if the last expression is handling a traceback.
Metadata
Metadata
Assignees
Labels
Projects
Status
No status