Fixed checking that no debug messages were logged

This commit is contained in:
Andrew Murray 2023-11-17 08:37:46 +11:00
parent 67e1253202
commit 5f33175b20

View File

@ -1,4 +1,5 @@
import io import io
import logging
import os import os
import shutil import shutil
import sys import sys
@ -1014,18 +1015,13 @@ class TestImage:
except OSError as e: except OSError as e:
assert str(e) == "buffer overrun when reading image file" assert str(e) == "buffer overrun when reading image file"
@pytest.fixture(scope="function") def test_close_graceful(self, caplog):
def inject_caplog(self, caplog):
self._caplog = caplog
@pytest.mark.usefixtures("inject_caplog")
def test_close_graceful(self):
with Image.open("Tests/images/hopper.jpg") as im: with Image.open("Tests/images/hopper.jpg") as im:
copy = im.copy() copy = im.copy()
with caplog.at_level(logging.DEBUG):
im.close() im.close()
copy.close() copy.close()
assert len(caplog.records) == 0
assert len(self._caplog.records) == 0
assert im.fp is None assert im.fp is None