Skip to content

Commit f106714

Browse files
authored
🐛 Fix relative path creation on Windows for fixtures (#333)
1 parent ab03254 commit f106714

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/test_path.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def absolute_file_path(tmp_path: pathlib.Path) -> pathlib.Path:
4444

4545
@pytest.fixture
4646
def relative_file_path(absolute_file_path: pathlib.Path) -> pathlib.Path:
47+
cwd = pathlib.Path.cwd()
48+
if os.name == 'nt' and absolute_file_path.anchor != cwd.anchor:
49+
# on windows, cant create relative path when paths are on different drives
50+
return absolute_file_path
4751
return pathlib.Path(os.path.relpath(absolute_file_path, os.getcwd()))
4852

4953

@@ -56,6 +60,10 @@ def absolute_directory_path(tmp_path: pathlib.Path) -> pathlib.Path:
5660

5761
@pytest.fixture
5862
def relative_directory_path(absolute_directory_path: pathlib.Path) -> pathlib.Path:
63+
cwd = pathlib.Path.cwd()
64+
if os.name == 'nt' and absolute_directory_path.anchor != cwd.anchor:
65+
# on windows, cant create relative path when paths are on different drives
66+
return absolute_directory_path
5967
return pathlib.Path(os.path.relpath(absolute_directory_path, os.getcwd()))
6068

6169

@@ -66,6 +74,10 @@ def absolute_new_path(tmp_path: pathlib.Path) -> pathlib.Path:
6674

6775
@pytest.fixture
6876
def relative_new_path(absolute_new_path: pathlib.Path) -> pathlib.Path:
77+
cwd = pathlib.Path.cwd()
78+
if os.name == 'nt' and absolute_new_path.anchor != cwd.anchor:
79+
# on windows, cant create relative path when paths are on different drives
80+
return absolute_new_path
6981
return pathlib.Path(os.path.relpath(absolute_new_path, os.getcwd()))
7082

7183

0 commit comments

Comments
 (0)