10
10
import sys
11
11
import time
12
12
import mmap
13
+ import warnings
13
14
import threading
14
15
from traceback import format_exception
15
16
from math import sqrt
20
21
import warnings
21
22
import pytest
22
23
23
- from importlib import reload
24
-
25
24
import joblib
26
25
from joblib import parallel
27
26
from joblib import dump , load
31
30
from joblib .test .common import np , with_numpy
32
31
from joblib .test .common import with_multiprocessing
33
32
from joblib .testing import (parametrize , raises , check_subprocess_call ,
34
- skipif , SkipTest , warns )
33
+ skipif , warns )
35
34
36
35
if mp is not None :
37
36
# Loky is not available if multiprocessing is not
@@ -181,7 +180,7 @@ def test_main_thread_renamed_no_warning(backend, monkeypatch):
181
180
monkeypatch .setattr (target = threading .current_thread (), name = 'name' ,
182
181
value = 'some_new_name_for_the_main_thread' )
183
182
184
- with warns ( None ) as warninfo :
183
+ with warnings . catch_warnings ( record = True ) as warninfo :
185
184
results = Parallel (n_jobs = 2 , backend = backend )(
186
185
delayed (square )(x ) for x in range (3 ))
187
186
assert results == [0 , 1 , 4 ]
@@ -197,18 +196,21 @@ def test_main_thread_renamed_no_warning(backend, monkeypatch):
197
196
198
197
199
198
def _assert_warning_nested (backend , inner_n_jobs , expected ):
200
- with warnings .catch_warnings (record = True ) as records :
199
+ with warnings .catch_warnings (record = True ) as warninfo :
201
200
warnings .simplefilter ("always" )
202
201
parallel_func (backend = backend , inner_n_jobs = inner_n_jobs )
203
202
204
- messages = [w .message for w in records ]
203
+ warninfo = [w .message for w in warninfo ]
205
204
if expected :
206
- # with threading, we might see more that one records
207
- if messages :
208
- return 'backed parallel loops cannot' in messages [0 ].args [0 ]
205
+ # with threading, we might see more that one warninfo
206
+ if warninfo :
207
+ return (
208
+ len (warninfo ) == 1 and
209
+ 'backed parallel loops cannot' in warninfo [0 ].args [0 ]
210
+ )
209
211
return False
210
212
else :
211
- assert not messages
213
+ assert not warninfo
212
214
return True
213
215
214
216
@@ -251,11 +253,11 @@ def test_background_thread_parallelism(backend):
251
253
is_run_parallel = [False ]
252
254
253
255
def background_thread (is_run_parallel ):
254
- with warns ( None ) as records :
256
+ with warnings . catch_warnings ( record = True ) as warninfo :
255
257
Parallel (n_jobs = 2 )(
256
258
delayed (sleep )(.1 ) for _ in range (4 ))
257
- print (len (records ))
258
- is_run_parallel [0 ] = len (records ) == 0
259
+ print (len (warninfo ))
260
+ is_run_parallel [0 ] = len (warninfo ) == 0
259
261
260
262
t = threading .Thread (target = background_thread , args = (is_run_parallel ,))
261
263
t .start ()
@@ -1180,7 +1182,7 @@ def test_memmap_with_big_offset(tmpdir):
1180
1182
1181
1183
1182
1184
def test_warning_about_timeout_not_supported_by_backend ():
1183
- with warns ( None ) as warninfo :
1185
+ with warnings . catch_warnings ( record = True ) as warninfo :
1184
1186
Parallel (timeout = 1 )(delayed (square )(i ) for i in range (50 ))
1185
1187
assert len (warninfo ) == 1
1186
1188
w = warninfo [0 ]
0 commit comments