1+ """
2+ emsarray test suite.
3+
4+ .. option --dask-scheduler <scheduler>
5+
6+ Set the scheduler for dask.
7+ Currently the test suite segfaults when the default scheduler is used.
8+ The scheduler is overridden to be 'synchronous', which avoids this issue.
9+ Use this flag to choose a different scheduler for testing fixes to the segfault.
10+ """
111import logging
212import pathlib
313from unittest import mock
414
15+ import dask
516import pytest
617
718import emsarray
@@ -20,6 +31,39 @@ def pytest_runtest_setup(item):
2031 item .fixturenames .append ("matplotlib_backend" )
2132
2233
34+ def pytest_addoption (parser ):
35+ parser .addoption (
36+ "--dask-scheduler" , type = str , action = "store" , default = "synchronous" ,
37+ help = (
38+ "Set the dask scheduler. Valid options include `synchronous' (the default), "
39+ "`distributed', `multiprocessing', `processes', `single-threaded', "
40+ "`sync', `synchronous', `threading', `threads'."
41+ ))
42+
43+
44+ @pytest .fixture (autouse = True , scope = 'session' )
45+ def disable_dask_threads (request ):
46+ """
47+ Currently the tests will regularly segfault while subsetting ugrid datasets.
48+ This only happens when using the latest dependencies installed from PyPI.
49+ Using older dependencies from PyPI or using latest dependencies from
50+ conda-forge continues to work fine.
51+
52+ Disabling dask multithreading stops the issue.
53+ This is a temporary work around while the issue is investigated.
54+
55+ To restore the default behaviour switch to the 'threads' scheduler:
56+
57+ $ pytest --dask-scheduler 'threads'
58+
59+ See also
60+ --------
61+ :option:`--dask-scheduler`
62+ https://github.com/csiro-coasts/emsarray/issues/139
63+ """
64+ dask .config .set (scheduler = request .config .option .dask_scheduler )
65+
66+
2367@pytest .fixture
2468def matplotlib_backend (
2569 request : pytest .FixtureRequest ,
0 commit comments