Merge "test: fix module state pollution"

This commit is contained in:
Zuul
2025-09-16 16:57:57 +00:00
committed by Gerrit Code Review

View File

@@ -5029,19 +5029,18 @@ class DiskFileMixin(BaseDiskFileTestMixin):
self.assertEqual(raised.exception.errno, errno.EACCES) self.assertEqual(raised.exception.errno, errno.EACCES)
def test_create_close_oserror(self): def test_create_close_oserror(self):
# This is a horrible hack so you can run this test in isolation. err = OSError(errno.EACCES, os.strerror(errno.EACCES))
# Some of the ctypes machinery calls os.close(), and that runs afoul # Disable fallocate for this test. Otherwise, the ctypes machinery may
# of our mock. # also call os.close (for example, when this test is run in isolation),
with mock.patch.object(utils, '_sys_fallocate', None): # but we're only interested in what diskfile is doing.
utils.disable_fallocate() with mock.patch.object(utils, '_fallocate_enabled', False):
df = self.df_mgr.get_diskfile(self.existing_device, '0', 'abc', df = self.df_mgr.get_diskfile(self.existing_device, '0', 'abc',
'123', 'xyz', policy=POLICIES.legacy) '123', 'xyz', policy=POLICIES.legacy)
with mock.patch("swift.obj.diskfile.os.close", with mock.patch("swift.obj.diskfile.os.close") as mock_close:
mock.MagicMock(side_effect=OSError( mock_close.side_effect = err
errno.EACCES, os.strerror(errno.EACCES)))): with df.create(size=200) as dfw:
with df.create(size=200): fd = dfw._fd
pass self.assertEqual([mock.call(fd)], mock_close.call_args_list)
def test_write_metadata(self): def test_write_metadata(self):
df, df_data = self._create_test_file(b'1234567890') df, df_data = self._create_test_file(b'1234567890')