Commit 2d57d5c 1 parent faeb161 commit 2d57d5c Copy full SHA for 2d57d5c
File tree 3 files changed +28
-14
lines changed
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(
556
556
path = path [:i ]
557
557
anchor = absolutepath (current / path )
558
558
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 :
570
562
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 :
572
566
self ._try_load_conftest (anchor , namespace .importmode , rootpath )
573
567
foundanchor = True
574
568
if not foundanchor :
Original file line number Diff line number Diff line change @@ -1254,7 +1254,7 @@ def test_initial_conftests_with_testpaths(pytester: Pytester) -> None:
1254
1254
textwrap .dedent (
1255
1255
"""
1256
1256
def pytest_sessionstart(session):
1257
- raise Exception("pytest_sessionstart hook is successfully run")
1257
+ raise Exception("pytest_sessionstart hook successfully run")
1258
1258
"""
1259
1259
)
1260
1260
)
@@ -1266,10 +1266,29 @@ def pytest_sessionstart(session):
1266
1266
)
1267
1267
result = pytester .runpytest ()
1268
1268
result .stdout .fnmatch_lines (
1269
- "INTERNALERROR* Exception: pytest_sessionstart hook is successfully run"
1269
+ "INTERNALERROR* Exception: pytest_sessionstart hook successfully run"
1270
1270
)
1271
1271
1272
1272
1273
+ def test_large_option_breaks_initial_conftests (pytester : Pytester ) -> None :
1274
+ """Long option values do not break initial conftests handling (#10169)."""
1275
+ option_value = "x" * 1024 * 1000
1276
+ pytester .makeconftest (
1277
+ """
1278
+ def pytest_addoption(parser):
1279
+ parser.addoption("--xx", default=None)
1280
+ """
1281
+ )
1282
+ pytester .makepyfile (
1283
+ f"""
1284
+ def test_foo(request):
1285
+ assert request.config.getoption("xx") == { option_value !r}
1286
+ """
1287
+ )
1288
+ result = pytester .runpytest (f"--xx={ option_value } " )
1289
+ assert result .ret == 0
1290
+
1291
+
1273
1292
def test_collect_symlink_file_arg (pytester : Pytester ) -> None :
1274
1293
"""Collect a direct symlink works even if it does not match python_files (#4325)."""
1275
1294
real = pytester .makepyfile (
You can’t perform that action at this time.
0 commit comments