File tree Expand file tree Collapse file tree 3 files changed +28
-14
lines changed Expand file tree Collapse file tree 3 files changed +28
-14
lines changed Original file line number Diff line number Diff line change 1+ Fix bug where very long option names could cause pytest to break with ``OSError: [Errno 36] File name too long `` on some systems.
Original file line number Diff line number Diff line change @@ -556,19 +556,13 @@ def _set_initial_conftests(
556556 path = path [:i ]
557557 anchor = absolutepath (current / path )
558558
559- # On Python 3.7 on Windows, anchor.exists() might raise
560- # if the anchor contains glob characters (for example "*//tests"), specially
561- # in the case of the 'testpaths' ini option.
562- # Using an explicit version check to remove this code later once
563- # Python 3.7 is dropped.
564- if sys .version_info [:2 ] == (3 , 7 ):
565- try :
566- anchor_exists = anchor .exists ()
567- except OSError : # pragma: no cover
568- anchor_exists = False
569- else :
559+ # Ensure we do not break if what appears to be an anchor
560+ # is in fact a very long option (#10169).
561+ try :
570562 anchor_exists = anchor .exists ()
571- if anchor_exists : # We found some file object.
563+ except OSError : # pragma: no cover
564+ anchor_exists = False
565+ if anchor_exists :
572566 self ._try_load_conftest (anchor , namespace .importmode , rootpath )
573567 foundanchor = True
574568 if not foundanchor :
Original file line number Diff line number Diff line change @@ -1253,7 +1253,7 @@ def test_initial_conftests_with_testpaths(pytester: Pytester) -> None:
12531253 textwrap .dedent (
12541254 """
12551255 def pytest_sessionstart(session):
1256- raise Exception("pytest_sessionstart hook is successfully run")
1256+ raise Exception("pytest_sessionstart hook successfully run")
12571257 """
12581258 )
12591259 )
@@ -1265,10 +1265,29 @@ def pytest_sessionstart(session):
12651265 )
12661266 result = pytester .runpytest ()
12671267 result .stdout .fnmatch_lines (
1268- "INTERNALERROR* Exception: pytest_sessionstart hook is successfully run"
1268+ "INTERNALERROR* Exception: pytest_sessionstart hook successfully run"
12691269 )
12701270
12711271
1272+ def test_large_option_breaks_initial_conftests (pytester : Pytester ) -> None :
1273+ """Long option values do not break initial conftests handling (#10169)."""
1274+ option_value = "x" * 1024 * 1000
1275+ pytester .makeconftest (
1276+ """
1277+ def pytest_addoption(parser):
1278+ parser.addoption("--xx", default=None)
1279+ """
1280+ )
1281+ pytester .makepyfile (
1282+ f"""
1283+ def test_foo(request):
1284+ assert request.config.getoption("xx") == { option_value !r}
1285+ """
1286+ )
1287+ result = pytester .runpytest (f"--xx={ option_value } " )
1288+ assert result .ret == 0
1289+
1290+
12721291def test_collect_symlink_file_arg (pytester : Pytester ) -> None :
12731292 """Collect a direct symlink works even if it does not match python_files (#4325)."""
12741293 real = pytester .makepyfile (
You can’t perform that action at this time.
0 commit comments