示例工程 19-threading-gil-multiprocessing
19-threading-gil-multiprocessing/04-process-pool/test_process_pool.py
"""test_process_pool.py"""
from __future__ import annotations
import pytest
from process_pool import cpu_work, main, pooled, serial
def test_cpu_work() -> None:
assert cpu_work(10) == 285
def test_serial_and_pooled_agree() -> None:
serial_results, _ = serial(2)
pooled_results, _ = pooled(2, 2)
assert serial_results == pooled_results
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
main()
out = capsys.readouterr().out
assert "same: True" in out
assert "pooled:" in out