|
13 | 13 | from dask.base import normalize_seq |
14 | 14 | else: |
15 | 15 | from dask.tokenize import normalize_seq |
16 | | -from filelock import FileLock |
| 16 | + |
| 17 | +import dask.distributed as dd |
17 | 18 | from scipy import sparse |
18 | 19 |
|
19 | 20 | import anndata as ad |
20 | 21 | from anndata.tests.helpers import subset_func # noqa: F401 |
21 | 22 |
|
22 | 23 | if TYPE_CHECKING: |
23 | | - from collections.abc import Generator |
24 | 24 | from types import EllipsisType |
25 | 25 |
|
26 | 26 |
|
@@ -77,37 +77,17 @@ def equivalent_ellipsis_index( |
77 | 77 | return ellipsis_index_with_equivalent[1] |
78 | 78 |
|
79 | 79 |
|
80 | | -@pytest.fixture(scope="session") |
81 | | -def local_cluster_addr( |
82 | | - tmp_path_factory: pytest.TempPathFactory, worker_id: str |
83 | | -) -> Generator[str, None, None]: |
84 | | - # Adapted from https://pytest-xdist.readthedocs.io/en/latest/how-to.html#making-session-scoped-fixtures-execute-only-once |
85 | | - import dask.distributed as dd |
86 | | - |
87 | | - def make_cluster() -> dd.LocalCluster: |
88 | | - return dd.LocalCluster(n_workers=1, threads_per_worker=1) |
89 | | - |
90 | | - if worker_id == "master": |
91 | | - with make_cluster() as cluster: |
92 | | - yield cluster.scheduler_address |
93 | | - return |
94 | | - |
95 | | - # get the temp directory shared by all workers |
96 | | - root_tmp_dir = tmp_path_factory.getbasetemp().parent |
97 | | - |
98 | | - fn = root_tmp_dir / "dask_scheduler_address.txt" |
99 | | - lock = FileLock(str(fn) + ".lock") |
100 | | - lock.acquire() # can’t use context manager, because we need to release the lock before yielding |
101 | | - address = fn.read_text() if fn.is_file() else None |
102 | | - if address: |
103 | | - lock.release() |
104 | | - yield address |
105 | | - return |
106 | | - |
107 | | - with make_cluster() as cluster: |
108 | | - fn.write_text(cluster.scheduler_address) |
109 | | - lock.release() |
110 | | - yield cluster.scheduler_address |
| 80 | +@pytest.fixture( |
| 81 | + scope="session", |
| 82 | + params=[ |
| 83 | + pytest.param( |
| 84 | + dd.LocalCluster(n_workers=1, threads_per_worker=1), |
| 85 | + # marks=pytest.mark.xdist_group("dask"), # if we ever want to do this setup only once |
| 86 | + ) |
| 87 | + ], |
| 88 | +) |
| 89 | +def local_cluster_addr(request): |
| 90 | + return request.param |
111 | 91 |
|
112 | 92 |
|
113 | 93 | ##################### |
|
0 commit comments