Preserve legacy API options in worker init

This commit is contained in:
Miro 2026-05-18 18:24:04 +02:00
parent ee03327c82
commit b77b354b7f
3 changed files with 50 additions and 9 deletions

View file

@ -289,9 +289,14 @@ def test_acquire_when_multiprocessing_pool_can_initialize():
This simulates the behaviour on most common platforms.
"""
with mock.patch("multiprocessing.Pool") as pool:
result = checker._try_initialize_processpool(2, [])
options = mock.Mock()
result = checker._try_initialize_processpool(2, [], options)
pool.assert_called_once_with(2, checker._mp_init, initargs=([],))
pool.assert_called_once_with(
2,
checker._mp_init,
initargs=([], options),
)
assert result is pool.return_value
@ -308,9 +313,14 @@ def test_acquire_when_multiprocessing_pool_can_not_initialize():
https://github.com/python/cpython/blob/4e02981de0952f54bf87967f8e10d169d6946b40/Lib/multiprocessing/synchronize.py#L30-L33
"""
with mock.patch("multiprocessing.Pool", side_effect=ImportError) as pool:
result = checker._try_initialize_processpool(2, [])
options = mock.Mock()
result = checker._try_initialize_processpool(2, [], options)
pool.assert_called_once_with(2, checker._mp_init, initargs=([],))
pool.assert_called_once_with(
2,
checker._mp_init,
initargs=([], options),
)
assert result is None

View file

@ -73,6 +73,23 @@ def test_jobs_count_limited_to_file_count():
assert manager.jobs == 2
def test_mp_init_preserves_supplied_options():
parsed_plugins = mock.Mock(checkers="parsed-checkers")
parsed_options = mock.Mock()
options_override = mock.Mock()
with (
mock.patch.object(checker, "_mp", None),
mock.patch.object(
checker,
"parse_args",
return_value=(parsed_plugins, parsed_options),
),
):
checker._mp_init([], options_override)
assert checker._mp == ("parsed-checkers", options_override)
def test_make_checkers():
"""Verify that we create a list of FileChecker instances."""
style_guide = style_guide_mock()