Enforce usage of fork method on macOS

This commit is contained in:
Florent 2022-07-24 14:06:56 +02:00
parent e8f9eb369a
commit 79a4316055
3 changed files with 30 additions and 8 deletions

View file

@ -1,6 +1,7 @@
"""Tests for the Manager object for FileCheckers."""
import errno
import multiprocessing
import platform
from unittest import mock
import pytest
@ -51,14 +52,28 @@ def test_oserrors_are_reraised(_):
assert serial.call_count == 0
@mock.patch.object(platform, "system")
@mock.patch.object(multiprocessing, "get_start_method", return_value="spawn")
def test_multiprocessing_is_disabled(_):
def test_multiprocessing_is_disabled(_, mock_system):
"""Verify not being able to import multiprocessing forces jobs to 0."""
style_guide = style_guide_mock()
manager = checker.Manager(style_guide, finder.Checkers([], [], []))
assert manager.jobs == 0
@mock.patch.object(platform, "system", return_value="Darwin")
@mock.patch.object(multiprocessing, "get_start_method", return_value="spawn")
def test_multiprocessing_is_enabled_for_macos(_, mock_system):
"""Verify jobs are returned on macOS.
Since Python 3.8, `spawn` is the default value on macOS, which is
not currently supported by flake8.
"""
style_guide = style_guide_mock()
manager = checker.Manager(style_guide, finder.Checkers([], [], []))
assert manager.jobs > 0
def test_multiprocessing_cpu_count_not_implemented():
"""Verify that jobs is 0 if cpu_count is unavailable."""
style_guide = style_guide_mock()