34
34
import shutil
35
35
import hashlib
36
36
import inspect
37
+ import logging
37
38
import tempfile
38
39
import warnings
39
40
import contextlib
54
55
{actual_path}"""
55
56
56
57
57
- def _download_file (baseline , filename ):
58
- # Note that baseline can be a comma-separated list of URLs that we can
59
- # then treat as mirrors
60
- for base_url in baseline .split (',' ):
61
- try :
62
- u = urlopen (base_url + filename )
63
- content = u .read ()
64
- except Exception as e :
65
- warnings .warn ('Downloading {0} failed: {1}' .format (base_url + filename , e ))
66
- else :
67
- break
68
- else :
69
- raise Exception ("Could not download baseline image from any of the "
70
- "available URLs" )
71
- result_dir = Path (tempfile .mkdtemp ())
72
- filename = result_dir / 'downloaded'
73
- with open (str (filename ), 'wb' ) as tmpfile :
74
- tmpfile .write (content )
75
- return Path (filename )
76
-
77
-
78
58
def _hash_file (in_stream ):
79
59
"""
80
60
Hashes an already opened file.
@@ -292,6 +272,12 @@ def __init__(self,
292
272
self ._test_results = {}
293
273
self ._test_stats = None
294
274
275
+ # https://stackoverflow.com/questions/51737378/how-should-i-log-in-my-pytest-plugin
276
+ # turn debug prints on only if "-vv" or more passed
277
+ level = logging .DEBUG if config .option .verbose > 1 else logging .INFO
278
+ logging .basicConfig (level = level )
279
+ self .logger = logging .getLogger ('pytest-mpl' )
280
+
295
281
def get_compare (self , item ):
296
282
"""
297
283
Return the mpl_image_compare marker for the given item.
@@ -364,6 +350,26 @@ def get_baseline_directory(self, item):
364
350
365
351
return baseline_dir
366
352
353
+ def _download_file (self , baseline , filename ):
354
+ # Note that baseline can be a comma-separated list of URLs that we can
355
+ # then treat as mirrors
356
+ for base_url in baseline .split (',' ):
357
+ try :
358
+ u = urlopen (base_url + filename )
359
+ content = u .read ()
360
+ except Exception as e :
361
+ self .logger .info (f'Downloading { base_url + filename } failed: { repr (e )} ' )
362
+ else :
363
+ break
364
+ else :
365
+ raise Exception ("Could not download baseline image from any of the "
366
+ "available URLs" )
367
+ result_dir = Path (tempfile .mkdtemp ())
368
+ filename = result_dir / 'downloaded'
369
+ with open (str (filename ), 'wb' ) as tmpfile :
370
+ tmpfile .write (content )
371
+ return Path (filename )
372
+
367
373
def obtain_baseline_image (self , item , target_dir ):
368
374
"""
369
375
Copy the baseline image to our working directory.
@@ -378,7 +384,7 @@ def obtain_baseline_image(self, item, target_dir):
378
384
if baseline_remote :
379
385
# baseline_dir can be a list of URLs when remote, so we have to
380
386
# pass base and filename to download
381
- baseline_image = _download_file (baseline_dir , filename )
387
+ baseline_image = self . _download_file (baseline_dir , filename )
382
388
else :
383
389
baseline_image = (baseline_dir / filename ).absolute ()
384
390
0 commit comments