Changed how pytest reacts to long filenames and changed its test
This commit is contained in:
parent
3f770a3568
commit
a057806d4f
|
@ -529,14 +529,12 @@ class PytestPluginManager(PluginManager):
|
||||||
path = path[:i]
|
path = path[:i]
|
||||||
anchor = absolutepath(current / path)
|
anchor = absolutepath(current / path)
|
||||||
try:
|
try:
|
||||||
if anchor.exists(): # we found some file object
|
anchor_exists = anchor.exists()
|
||||||
|
except OSError:
|
||||||
|
anchor_exists = False
|
||||||
|
if anchor_exists:
|
||||||
self._try_load_conftest(anchor, namespace.importmode, rootpath)
|
self._try_load_conftest(anchor, namespace.importmode, rootpath)
|
||||||
foundanchor = True
|
foundanchor = True
|
||||||
print(str(anchor))
|
|
||||||
except OSError:
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
raise pytest.UsageError(f"filename is too long: {anchor}")
|
|
||||||
if not foundanchor:
|
if not foundanchor:
|
||||||
self._try_load_conftest(current, namespace.importmode, rootpath)
|
self._try_load_conftest(current, namespace.importmode, rootpath)
|
||||||
|
|
||||||
|
|
|
@ -1780,24 +1780,25 @@ def test_help_and_version_after_argument_error(pytester: Pytester) -> None:
|
||||||
assert result.ret == ExitCode.USAGE_ERROR
|
assert result.ret == ExitCode.USAGE_ERROR
|
||||||
|
|
||||||
|
|
||||||
def test_filename_too_long(pytester: Pytester) -> None:
|
def test_filename_too_long(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
|
||||||
|
"""And OSError may be raised if filename is too long. This test ensures
|
||||||
|
the issue of that error not being caught does not regress."""
|
||||||
|
|
||||||
path_str = (
|
path_str = (
|
||||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" * 50
|
||||||
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
||||||
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
||||||
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
||||||
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def FilePathTooLong(p):
|
||||||
|
if len(str(p)) >= 200:
|
||||||
|
raise OSError()
|
||||||
|
|
||||||
|
monkeypatch.setattr(Path, "exists", FilePathTooLong, raising=True)
|
||||||
|
|
||||||
config = pytester.parseconfig()
|
config = pytester.parseconfig()
|
||||||
config.known_args_namespace.file_or_dir.append(path_str)
|
config.known_args_namespace.file_or_dir.append(path_str)
|
||||||
pytest.raises(
|
config.pluginmanager._set_initial_conftests(
|
||||||
UsageError,
|
config.known_args_namespace, rootpath=config.rootpath
|
||||||
config.pluginmanager._set_initial_conftests,
|
|
||||||
config.known_args_namespace,
|
|
||||||
rootpath=config.rootpath,
|
|
||||||
)
|
)
|
||||||
result = pytester.runpytest(path_str)
|
|
||||||
assert result.ret == ExitCode.USAGE_ERROR
|
|
||||||
|
|
||||||
|
|
||||||
def test_help_formatter_uses_py_get_terminal_width(monkeypatch: MonkeyPatch) -> None:
|
def test_help_formatter_uses_py_get_terminal_width(monkeypatch: MonkeyPatch) -> None:
|
||||||
|
|
Loading…
Reference in New Issue