44import os
55from pathlib import Path
66import shutil
7- from subprocess import Popen , PIPE
87import sys
98
9+ from matplotlib .testing import subprocess_run_for_testing
1010import pytest
1111
1212
@@ -19,15 +19,11 @@ def build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):
1919 extra_args = [] if extra_args is None else extra_args
2020 cmd = [sys .executable , '-msphinx' , '-W' , '-b' , 'html' ,
2121 '-d' , str (doctree_dir ), str (source_dir ), str (html_dir ), * extra_args ]
22- try :
23- proc = Popen (cmd , stdout = PIPE , stderr = PIPE , universal_newlines = True ,
24- env = {** os .environ , "MPLBACKEND" : "" })
25- except BlockingIOError :
26- if sys .platform == "cygwin" :
27- pytest .xfail ("Fork failure" )
28- else :
29- raise
30- out , err = proc .communicate ()
22+ proc = subprocess_run_for_testing (
23+ cmd , capture_output = True , universal_newlines = True ,
24+ env = {** os .environ , "MPLBACKEND" : "" })
25+ out = proc .stdout
26+ err = proc .stderr
3127
3228 assert proc .returncode == 0 , \
3329 f"sphinx build failed with stdout:\n { out } \n stderr:\n { err } \n "
@@ -50,17 +46,12 @@ def test_tinypages(tmp_path):
5046 # On CI, gcov emits warnings (due to agg headers being included with the
5147 # same name in multiple extension modules -- but we don't care about their
5248 # coverage anyways); hide them using GCOV_ERROR_FILE.
53- try :
54- proc = Popen (
55- cmd , stdout = PIPE , stderr = PIPE , universal_newlines = True ,
56- env = {** os .environ , "MPLBACKEND" : "" , "GCOV_ERROR_FILE" : os .devnull }
57- )
58- except BlockingIOError :
59- if sys .platform == "cygwin" :
60- pytest .xfail ("Fork failure" )
61- else :
62- raise
63- out , err = proc .communicate ()
49+ proc = subprocess_run_for_testing (
50+ cmd , capture_output = True , universal_newlines = True ,
51+ env = {** os .environ , "MPLBACKEND" : "" , "GCOV_ERROR_FILE" : os .devnull }
52+ )
53+ out = proc .stdout
54+ err = proc .stderr
6455
6556 # Build the pages with warnings turned into errors
6657 build_sphinx_html (tmp_path , doctree_dir , html_dir )
0 commit comments