99import json
1010import shutil
1111import sys
12+ from collections .abc import Callable
13+ from contextlib import nullcontext
1214from dataclasses import asdict , dataclass
1315from pathlib import Path
14- from typing import Literal
1516
1617import pytest
1718
@@ -38,33 +39,27 @@ def result(self) -> object:
3839 return self .value
3940
4041
41- class _DummyExecutor :
42- def __init__ (self , max_workers : int | None = None ) -> None :
43- self .max_workers = max_workers
44-
45- def __enter__ (self ) -> _DummyExecutor :
46- return self
47-
48- def __exit__ (
49- self ,
50- exc_type : type [BaseException ] | None ,
51- exc : BaseException | None ,
52- tb : object | None ,
53- ) -> Literal [False ]:
54- return False
42+ @dataclass (slots = True )
43+ class _InlineExecutor :
44+ max_workers : int | None = None
5545
5646 def submit (
5747 self ,
58- fn : object ,
48+ fn : Callable [..., object ] ,
5949 * args : object ,
6050 ** kwargs : object ,
6151 ) -> _DummyFuture :
62- assert callable (fn )
6352 return _DummyFuture (fn (* args , ** kwargs ))
6453
6554
55+ def _dummy_process_pool_executor (
56+ max_workers : int | None = None ,
57+ ) -> object :
58+ return nullcontext (_InlineExecutor (max_workers = max_workers ))
59+
60+
6661def _patch_parallel (monkeypatch : pytest .MonkeyPatch ) -> None :
67- monkeypatch .setattr (pipeline , "ProcessPoolExecutor" , _DummyExecutor )
62+ monkeypatch .setattr (pipeline , "ProcessPoolExecutor" , _dummy_process_pool_executor )
6863 monkeypatch .setattr (pipeline , "as_completed" , lambda futures : futures )
6964
7065
0 commit comments