Skip to content

Commit 96893ca

Browse files
committed
retry image comparison on exception
1 parent 6c01d49 commit 96893ca

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tests/_base_testing.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Base test setup for the psy-simple test suite."""
22

3-
43
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
54
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
65
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
@@ -11,6 +10,7 @@
1110
import os
1211
import subprocess as spr
1312
import sys
13+
import time
1414
from unittest import TestCase
1515

1616
import numpy as np
@@ -97,11 +97,21 @@ def compare_figures(self, fname, tol=5, **kwargs):
9797
from matplotlib.testing.compare import compare_images
9898

9999
plt.savefig(os.path.join(self.odir, fname), **kwargs)
100-
results = compare_images(
101-
os.path.join(ref_dir, fname),
102-
os.path.join(self.odir, fname),
103-
tol=tol,
104-
)
100+
try:
101+
results = compare_images(
102+
os.path.join(ref_dir, fname),
103+
os.path.join(self.odir, fname),
104+
tol=tol,
105+
)
106+
except Exception:
107+
# output file might be empty because not yet written, so just try
108+
# again
109+
time.sleep(3)
110+
results = compare_images(
111+
os.path.join(ref_dir, fname),
112+
os.path.join(self.odir, fname),
113+
tol=tol,
114+
)
105115
self.assertIsNone(results, msg=results)
106116

107117
def assertAlmostArrayEqual(

0 commit comments

Comments
 (0)