summaryrefslogtreecommitdiff
path: root/Lib/test/support/os_helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/support/os_helper.py')
-rw-r--r--Lib/test/support/os_helper.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index d9807a1e11..82a6de789c 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -455,6 +455,17 @@ def create_empty_file(filename):
os.close(fd)
+@contextlib.contextmanager
+def open_dir_fd(path):
+ """Open a file descriptor to a directory."""
+ assert os.path.isdir(path)
+ dir_fd = os.open(path, os.O_RDONLY)
+ try:
+ yield dir_fd
+ finally:
+ os.close(dir_fd)
+
+
def fs_is_case_insensitive(directory):
"""Detects if the file system for the specified directory
is case-insensitive."""