Skip to content

Commit 9ee5c1b

Browse files
authored
Use tempfile for creating a file in home directory for a IO test (#40122)
1 parent db495eb commit 9ee5c1b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pandas/tests/io/test_common.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import mmap
1010
import os
1111
from pathlib import Path
12+
import tempfile
1213

1314
import pytest
1415

@@ -119,10 +120,11 @@ def test_infer_compression_from_path(self, extension, expected, path_type):
119120
@pytest.mark.parametrize("path_type", [str, CustomFSPath, Path])
120121
def test_get_handle_with_path(self, path_type):
121122
# ignore LocalPath: it creates strange paths: /absolute/~/sometest
122-
filename = path_type("~/sometest")
123-
with icom.get_handle(filename, "w") as handles:
124-
assert os.path.isabs(handles.handle.name)
125-
assert os.path.expanduser(filename) == handles.handle.name
123+
with tempfile.TemporaryDirectory(dir=Path.home()) as tmp:
124+
filename = path_type("~/" + Path(tmp).name + "/sometest")
125+
with icom.get_handle(filename, "w") as handles:
126+
assert Path(handles.handle.name).is_absolute()
127+
assert os.path.expanduser(filename) == handles.handle.name
126128

127129
def test_get_handle_with_buffer(self):
128130
input_buffer = StringIO()

0 commit comments

Comments
 (0)