Consider this repro:
draft @ cat zip-tb.txt
>>> import zipfile
>>> import io
>>> zf = zipfile.ZipFile(io.BytesIO(), 'w')
>>> zf.foo # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AttributeError: ...
draft @ py -3.12 -m doctest zip-tb.txt
Exception 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 a ValueError atexit.
The issue only arises if the last expression in the doctest triggered a traceback and the zipfile was present in the traceback. Changing zf.foo to io.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.
Consider this repro:
The test runs fine, but triggers a
ValueErroratexit.The issue only arises if the last expression in the doctest triggered a traceback and the zipfile was present in the traceback. Changing
zf.footoio.fooor adding>>> passbypasses the error.I suspect there's a flaw in doctest that leaves resources unclosed if the last expression is handling a traceback.