Do not break on very long command-line options
`_set_initial_conftests` could break on some systems if a very long option was passed, because the `Path.exists()` call raises an `OSError` instead of returning `False`. Fix #10169
This commit is contained in:
@@ -1254,7 +1254,7 @@ def test_initial_conftests_with_testpaths(pytester: Pytester) -> None:
|
||||
textwrap.dedent(
|
||||
"""
|
||||
def pytest_sessionstart(session):
|
||||
raise Exception("pytest_sessionstart hook is successfully run")
|
||||
raise Exception("pytest_sessionstart hook successfully run")
|
||||
"""
|
||||
)
|
||||
)
|
||||
@@ -1266,10 +1266,29 @@ def test_initial_conftests_with_testpaths(pytester: Pytester) -> None:
|
||||
)
|
||||
result = pytester.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"INTERNALERROR* Exception: pytest_sessionstart hook is successfully run"
|
||||
"INTERNALERROR* Exception: pytest_sessionstart hook successfully run"
|
||||
)
|
||||
|
||||
|
||||
def test_large_option_breaks_initial_conftests(pytester: Pytester) -> None:
|
||||
"""Long option values do not break initial conftests handling (#10169)."""
|
||||
option_value = "x" * 1024 * 1000
|
||||
pytester.makeconftest(
|
||||
"""
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--xx", default=None)
|
||||
"""
|
||||
)
|
||||
pytester.makepyfile(
|
||||
f"""
|
||||
def test_foo(request):
|
||||
assert request.config.getoption("xx") == {option_value!r}
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(f"--xx={option_value}")
|
||||
assert result.ret == 0
|
||||
|
||||
|
||||
def test_collect_symlink_file_arg(pytester: Pytester) -> None:
|
||||
"""Collect a direct symlink works even if it does not match python_files (#4325)."""
|
||||
real = pytester.makepyfile(
|
||||
|
||||
Reference in New Issue
Block a user