Fix crash when passing a very long cmdline argument (#11404)
Fixes #11394
This commit is contained in:
@@ -36,6 +36,7 @@ from _pytest.outcomes import exit
|
||||
from _pytest.pathlib import absolutepath
|
||||
from _pytest.pathlib import bestrelpath
|
||||
from _pytest.pathlib import fnmatch_ex
|
||||
from _pytest.pathlib import safe_exists
|
||||
from _pytest.pathlib import visit
|
||||
from _pytest.reports import CollectReport
|
||||
from _pytest.reports import TestReport
|
||||
@@ -888,7 +889,7 @@ def resolve_collection_argument(
|
||||
strpath = search_pypath(strpath)
|
||||
fspath = invocation_path / strpath
|
||||
fspath = absolutepath(fspath)
|
||||
if not fspath.exists():
|
||||
if not safe_exists(fspath):
|
||||
msg = (
|
||||
"module or package not found: {arg} (missing __init__.py?)"
|
||||
if as_pypath
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import atexit
|
||||
import contextlib
|
||||
import errno
|
||||
import fnmatch
|
||||
import importlib.util
|
||||
import itertools
|
||||
@@ -773,3 +774,13 @@ def bestrelpath(directory: Path, dest: Path) -> str:
|
||||
# Forward from base to dest.
|
||||
*reldest.parts,
|
||||
)
|
||||
|
||||
|
||||
def safe_exists(p: Path) -> bool:
|
||||
"""Like Path.exists(), but account for input arguments that might be too long (#11394)."""
|
||||
try:
|
||||
return p.exists()
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENAMETOOLONG:
|
||||
return False
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user