diff --git a/pandas/tests/io/test_common.py b/pandas/tests/io/test_common.py index db742fb69dd10..e1dcec56913f9 100644 --- a/pandas/tests/io/test_common.py +++ b/pandas/tests/io/test_common.py @@ -9,6 +9,7 @@ import mmap import os from pathlib import Path +import tempfile import pytest @@ -119,10 +120,11 @@ def test_infer_compression_from_path(self, extension, expected, path_type): @pytest.mark.parametrize("path_type", [str, CustomFSPath, Path]) def test_get_handle_with_path(self, path_type): # ignore LocalPath: it creates strange paths: /absolute/~/sometest - filename = path_type("~/sometest") - with icom.get_handle(filename, "w") as handles: - assert os.path.isabs(handles.handle.name) - assert os.path.expanduser(filename) == handles.handle.name + with tempfile.TemporaryDirectory(dir=Path.home()) as tmp: + filename = path_type("~/" + Path(tmp).name + "/sometest") + with icom.get_handle(filename, "w") as handles: + assert Path(handles.handle.name).is_absolute() + assert os.path.expanduser(filename) == handles.handle.name def test_get_handle_with_buffer(self): input_buffer = StringIO()