Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45a1d22

Browse files
committed
TST: Also output the actual error on svg backend tests using subprocess
Up to now the tests only checked the returncode of a test invoking subprocess, but didn't show the real error printed by the failing tests. Now we show print the original output on failure so that it is shown in the test output.
1 parent 9ff8535 commit 45a1d22

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,25 @@ def _test_determinism_save(filename, usetex):
153153
def _test_determinism(filename, usetex):
154154
import os
155155
import sys
156-
from subprocess import check_call
156+
from subprocess import check_output, STDOUT, CalledProcessError
157157
from nose.tools import assert_equal
158158
plots = []
159159
for i in range(3):
160-
check_call([sys.executable, '-R', '-c',
161-
'import matplotlib; '
162-
'matplotlib.use("svg"); '
163-
'from matplotlib.tests.test_backend_svg '
164-
'import _test_determinism_save;'
165-
'_test_determinism_save(%r, %r)' % (filename, usetex)])
160+
# Using check_output and setting stderr to STDOUT will capture the real
161+
# problem in the output property of the exception
162+
try:
163+
check_output([sys.executable, '-R', '-c',
164+
'import matplotlib; '
165+
'matplotlib.use("svg"); '
166+
'from matplotlib.tests.test_backend_svg '
167+
'import _test_determinism_save;'
168+
'_test_determinism_save(%r, %r)' % (filename, usetex)],
169+
stderr=STDOUT)
170+
except CalledProcessError as e:
171+
# it's easier to use utf8 and ask for forgiveness than try to figure
172+
# out what the current console has as an encoding :-/
173+
print(e.output.decode(encoding="utf-8", errors="ignore"))
174+
raise e
166175
with open(filename, 'rb') as fd:
167176
plots.append(fd.read())
168177
os.unlink(filename)

0 commit comments

Comments
 (0)