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

Skip to content

Commit ee7d467

Browse files
committed
TST: get coverage information out of isolated tk tests
1 parent 507bff4 commit ee7d467

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

lib/matplotlib/tests/test_backend_tk.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import platform
55
import re
66
import subprocess
7-
import sys
87

98
import pytest
109

10+
from matplotlib.testing import subprocess_run_helper
11+
1112
_test_timeout = 60 # A reasonably safe value for slower architectures.
1213

1314

@@ -20,9 +21,7 @@ def _isolated_tk_test(success_count, func=None):
2021
in a subprocess. See GH#18261
2122
2223
The decorated function must be fully self-contained, and thus perform
23-
all the imports it needs. Because its source is extracted and run by
24-
itself, coverage will consider it as not being run, so it should be marked
25-
with ``# pragma: no cover``
24+
all the imports it needs.
2625
"""
2726

2827
if func is None:
@@ -34,14 +33,10 @@ def _isolated_tk_test(success_count, func=None):
3433
@functools.wraps(func)
3534
def test_func():
3635
try:
37-
proc = subprocess.run(
38-
[sys.executable, "-c", f"{source}\n{func.__name__}()"],
39-
env={**os.environ, "MPLBACKEND": "TkAgg"},
40-
timeout=_test_timeout,
41-
stdout=subprocess.PIPE,
42-
stderr=subprocess.PIPE,
43-
check=True,
44-
universal_newlines=True,
36+
proc = subprocess_run_helper(
37+
__name__, func, timeout=_test_timeout,
38+
MPLBACKEND="TkAgg",
39+
MPL_TEST_ESCAPE_HATCH="1"
4540
)
4641
except subprocess.TimeoutExpired:
4742
pytest.fail("Subprocess timed out")
@@ -55,13 +50,14 @@ def test_func():
5550
assert not [line for line in proc.stderr.splitlines()
5651
if "OpenGL" not in line]
5752
assert proc.stdout.count("success") == success_count
58-
59-
return test_func
53+
if "MPL_TEST_ESCAPE_HATCH" in os.environ:
54+
return func
55+
else:
56+
return test_func
6057

6158

62-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
6359
@_isolated_tk_test(success_count=6) # len(bad_boxes)
64-
def test_blit(): # pragma: no cover
60+
def test_blit():
6561
import matplotlib.pyplot as plt
6662
import numpy as np
6763
import matplotlib.backends.backend_tkagg # noqa
@@ -88,9 +84,8 @@ def test_blit(): # pragma: no cover
8884
print("success")
8985

9086

91-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
9287
@_isolated_tk_test(success_count=1)
93-
def test_figuremanager_preserves_host_mainloop(): # pragma: no cover
88+
def test_figuremanager_preserves_host_mainloop():
9489
import tkinter
9590
import matplotlib.pyplot as plt
9691
success = []
@@ -116,10 +111,9 @@ def legitimate_quit():
116111
@pytest.mark.skipif(platform.python_implementation() != 'CPython',
117112
reason='PyPy does not support Tkinter threading: '
118113
'https://foss.heptapod.net/pypy/pypy/-/issues/1929')
119-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
120114
@pytest.mark.flaky(reruns=3)
121115
@_isolated_tk_test(success_count=1)
122-
def test_figuremanager_cleans_own_mainloop(): # pragma: no cover
116+
def test_figuremanager_cleans_own_mainloop():
123117
import tkinter
124118
import time
125119
import matplotlib.pyplot as plt
@@ -144,10 +138,9 @@ def target():
144138
thread.join()
145139

146140

147-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
148141
@pytest.mark.flaky(reruns=3)
149142
@_isolated_tk_test(success_count=0)
150-
def test_never_update(): # pragma: no cover
143+
def test_never_update():
151144
import tkinter
152145
del tkinter.Misc.update
153146
del tkinter.Misc.update_idletasks
@@ -171,9 +164,8 @@ def test_never_update(): # pragma: no cover
171164
# checks them.
172165

173166

174-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
175167
@_isolated_tk_test(success_count=2)
176-
def test_missing_back_button(): # pragma: no cover
168+
def test_missing_back_button():
177169
import matplotlib.pyplot as plt
178170
from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk
179171

0 commit comments

Comments
 (0)