Commit ddf42d7 1 parent 28ccf47 commit ddf42d7 Copy full SHA for ddf42d7
File tree 4 files changed +10
-22
lines changed
4 files changed +10
-22
lines changed Original file line number Diff line number Diff line change 59
59
from _pytest .pathlib import import_path
60
60
from _pytest .pathlib import ImportMode
61
61
from _pytest .pathlib import resolve_package_path
62
+ from _pytest .pathlib import safe_exists
62
63
from _pytest .stash import Stash
63
64
from _pytest .warning_types import PytestConfigWarning
64
65
from _pytest .warning_types import warn_explicit_for
@@ -562,12 +563,8 @@ def _set_initial_conftests(
562
563
anchor = absolutepath (current / path )
563
564
564
565
# Ensure we do not break if what appears to be an anchor
565
- # is in fact a very long option (#10169).
566
- try :
567
- anchor_exists = anchor .exists ()
568
- except OSError : # pragma: no cover
569
- anchor_exists = False
570
- if anchor_exists :
566
+ # is in fact a very long option (#10169, #11394).
567
+ if safe_exists (anchor ):
571
568
self ._try_load_conftest (anchor , importmode , rootpath )
572
569
foundanchor = True
573
570
if not foundanchor :
Original file line number Diff line number Diff line change 15
15
from _pytest .outcomes import fail
16
16
from _pytest .pathlib import absolutepath
17
17
from _pytest .pathlib import commonpath
18
+ from _pytest .pathlib import safe_exists
18
19
19
20
20
21
def _parse_ini_config (path : Path ) -> iniconfig .IniConfig :
@@ -147,14 +148,6 @@ def get_dir_from_path(path: Path) -> Path:
147
148
return path
148
149
return path .parent
149
150
150
- def safe_exists (path : Path ) -> bool :
151
- # This can throw on paths that contain characters unrepresentable at the OS level,
152
- # or with invalid syntax on Windows (https://bugs.python.org/issue35306)
153
- try :
154
- return path .exists ()
155
- except OSError :
156
- return False
157
-
158
151
# These look like paths but may not exist
159
152
possible_paths = (
160
153
absolutepath (get_file_part_from_node_id (arg ))
Original file line number Diff line number Diff line change 1
1
import atexit
2
2
import contextlib
3
- import errno
4
3
import fnmatch
5
4
import importlib .util
6
5
import itertools
@@ -780,7 +779,7 @@ def safe_exists(p: Path) -> bool:
780
779
"""Like Path.exists(), but account for input arguments that might be too long (#11394)."""
781
780
try :
782
781
return p .exists ()
783
- except OSError as e :
784
- if e . errno == errno . ENAMETOOLONG :
785
- return False
786
- raise
782
+ except ( ValueError , OSError ) :
783
+ # ValueError: stat: path too long for Windows
784
+ # OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect
785
+ return False
Original file line number Diff line number Diff line change @@ -688,7 +688,6 @@ def test_safe_exists(tmp_path: Path) -> None:
688
688
Path ,
689
689
"exists" ,
690
690
autospec = True ,
691
- side_effect = OSError ( errno . EIO , "another kind of error " ),
691
+ side_effect = ValueError ( "name too long " ),
692
692
):
693
- with pytest .raises (OSError ):
694
- _ = safe_exists (p )
693
+ assert safe_exists (p ) is False
You can’t perform that action at this time.
0 commit comments