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

Skip to content

Commit 0dfa854

Browse files
committed
TST: Ensure test_webagg subprocess is terminated
If the final communication times out or asserts, there is nothing to enforce that the subprocess is killed.
1 parent 835220b commit 0dfa854

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -481,24 +481,27 @@ def test_webagg():
481481
inspect.getsource(_test_interactive_impl)
482482
+ "\n_test_interactive_impl()", "{}"],
483483
env={**os.environ, "MPLBACKEND": "webagg", "SOURCE_DATE_EPOCH": "0"})
484-
url = "http://{}:{}".format(
485-
mpl.rcParams["webagg.address"], mpl.rcParams["webagg.port"])
484+
url = f'http://{mpl.rcParams["webagg.address"]}:{mpl.rcParams["webagg.port"]}'
486485
timeout = time.perf_counter() + _test_timeout
487-
while True:
488-
try:
489-
retcode = proc.poll()
490-
# check that the subprocess for the server is not dead
491-
assert retcode is None
492-
conn = urllib.request.urlopen(url)
493-
break
494-
except urllib.error.URLError:
495-
if time.perf_counter() > timeout:
496-
pytest.fail("Failed to connect to the webagg server.")
497-
else:
498-
continue
499-
conn.close()
500-
proc.send_signal(signal.SIGINT)
501-
assert proc.wait(timeout=_test_timeout) == 0
486+
try:
487+
while True:
488+
try:
489+
retcode = proc.poll()
490+
# check that the subprocess for the server is not dead
491+
assert retcode is None
492+
conn = urllib.request.urlopen(url)
493+
break
494+
except urllib.error.URLError:
495+
if time.perf_counter() > timeout:
496+
pytest.fail("Failed to connect to the webagg server.")
497+
else:
498+
continue
499+
conn.close()
500+
proc.send_signal(signal.SIGINT)
501+
assert proc.wait(timeout=_test_timeout) == 0
502+
finally:
503+
if proc.poll() is None:
504+
proc.kill()
502505

503506

504507
def _lazy_headless():

0 commit comments

Comments
 (0)