File tree 3 files changed +13
-8
lines changed
3 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 16
16
from _pytest .outcomes import fail
17
17
from _pytest .pathlib import absolutepath
18
18
from _pytest .pathlib import commonpath
19
+ from _pytest .pathlib import safe_exists
19
20
20
21
if TYPE_CHECKING :
21
22
from . import Config
@@ -151,14 +152,6 @@ def get_dir_from_path(path: Path) -> Path:
151
152
return path
152
153
return path .parent
153
154
154
- def safe_exists (path : Path ) -> bool :
155
- # This can throw on paths that contain characters unrepresentable at the OS level,
156
- # or with invalid syntax on Windows (https://bugs.python.org/issue35306)
157
- try :
158
- return path .exists ()
159
- except OSError :
160
- return False
161
-
162
155
# These look like paths but may not exist
163
156
possible_paths = (
164
157
absolutepath (get_file_part_from_node_id (arg ))
Original file line number Diff line number Diff line change @@ -798,6 +798,10 @@ def safe_exists(p: Path) -> bool:
798
798
"""Like Path.exists(), but account for input arguments that might be too long (#11394)."""
799
799
try :
800
800
return p .exists ()
801
+ except ValueError :
802
+ # Might be raised on Windows:
803
+ # ValueError: stat: path too long for Windows
804
+ return False
801
805
except OSError as e :
802
806
if e .errno == errno .ENAMETOOLONG :
803
807
return False
Original file line number Diff line number Diff line change @@ -684,6 +684,14 @@ def test_safe_exists(tmp_path: Path) -> None:
684
684
):
685
685
assert safe_exists (p ) is False
686
686
687
+ with unittest .mock .patch .object (
688
+ Path ,
689
+ "exists" ,
690
+ autospec = True ,
691
+ side_effect = ValueError ("name too long" ),
692
+ ):
693
+ assert safe_exists (p ) is False
694
+
687
695
with unittest .mock .patch .object (
688
696
Path ,
689
697
"exists" ,
You can’t perform that action at this time.
0 commit comments