8000 bpo-39488: Skip test_largefile tests if not enough disk space (GH-18261) · python/cpython@b39fb8e · GitHub
[go: up one dir, main page]

Skip to content

Commit b39fb8e

Browse files
authored
bpo-39488: Skip test_largefile tests if not enough disk space (GH-18261)
1 parent bf305cc commit b39fb8e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_largefile.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,24 @@ def test_seekable(self):
151151
self.assertTrue(f.seekable())
152152

153153

154+
def skip_no_disk_space(path, required):
155+
def decorator(fun):
156+
def wrapper(*args, **kwargs):
157+
if shutil.disk_usage(os.path.realpath(path)).free < required:
158+
hsize = int(required / 1024 / 1024)
159+
raise unittest.SkipTest(
160+
f"required {hsize} MiB of free disk space")
161+
return fun(*args, **kwargs)
162+
return wrapper
163+
return decorator
164+
165+
154166
class TestCopyfile(LargeFileTest, unittest.TestCase):
155167
open = staticmethod(io.open)
156168

169+
# Exact required disk space would be (size * 2), but let's give it a
170+
# bit more tolerance.
171+
@skip_no_disk_space(TESTFN, size * 2.5)
157172
def test_it(self):
158173
# Internally shutil.copyfile() can use "fast copy" methods like
159174
# os.sendfile().
@@ -200,6 +215,9 @@ def run(sock):
200215
self.thread.start()
201216
event.set()
202217

218+
# Exact required disk space would be (size * 2), but let's give it a
219+
# bit more tolerance.
220+
@skip_no_disk_space(TESTFN, size * 2.5)
203221
def test_it(self):
204222
port = find_unused_port()
205223
with socket.create_server(("", port)) as sock:

0 commit comments

Comments
 (0)
0