Skip to content

Commit b1378a7

Browse files
committed
parametrize multiprocessing test over different methods
1 parent 5dceb04 commit b1378a7

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tests/test_array.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import dataclasses
22
import json
33
import math
4+
import multiprocessing as mp
45
import pickle
56
import re
7+
import sys
68
from itertools import accumulate
79
from typing import TYPE_CHECKING, Any, Literal
810
from unittest import mock
@@ -1388,16 +1390,33 @@ def _index_array(arr: Array, index: Any) -> Any:
13881390
return arr[index]
13891391

13901392

1393+
@pytest.mark.parametrize(
1394+
"method",
1395+
[
1396+
pytest.param(
1397+
"fork",
1398+
marks=pytest.mark.skipif(
1399+
sys.platform in ("win32", "darwin"), reason="fork not supported on Windows or OSX"
1400+
),
1401+
),
1402+
"spawn",
1403+
pytest.param(
1404+
"forkserver",
1405+
marks=pytest.mark.skipif(
1406+
sys.platform == "win32", reason="forkserver not supported on Windows"
1407+
),
1408+
),
1409+
],
1410+
)
13911411
@pytest.mark.parametrize("store", ["local"], indirect=True)
1392-
def test_multiprocessing(store: Store) -> None:
1412+
def test_multiprocessing(store: Store, method: Literal["fork", "spawn"]) -> None:
13931413
"""
13941414
Test that arrays can be pickled and indexed in child processes
13951415
"""
13961416
data = np.arange(100)
13971417
arr = zarr.create_array(store=store, data=data)
1398-
from multiprocessing import Pool
1399-
1400-
pool = Pool()
1418+
ctx = mp.get_context(method)
1419+
pool = ctx.Pool()
14011420

1402-
results = pool.starmap(_index_array, [(arr, slice(len(data)))] * 3)
1421+
results = pool.starmap(_index_array, [(arr, slice(len(data)))])
14031422
assert all(np.array_equal(r, data) for r in results)

0 commit comments

Comments
 (0)