4
4
import platform
5
5
import re
6
6
import subprocess
7
- import sys
8
7
9
8
import pytest
10
9
10
+ from matplotlib .testing import subprocess_run_helper
11
+
11
12
_test_timeout = 60 # A reasonably safe value for slower architectures.
12
13
13
14
@@ -20,9 +21,7 @@ def _isolated_tk_test(success_count, func=None):
20
21
in a subprocess. See GH#18261
21
22
22
23
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.
26
25
"""
27
26
28
27
if func is None :
@@ -34,14 +33,10 @@ def _isolated_tk_test(success_count, func=None):
34
33
@functools .wraps (func )
35
34
def test_func ():
36
35
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"
45
40
)
46
41
except subprocess .TimeoutExpired :
47
42
pytest .fail ("Subprocess timed out" )
@@ -55,13 +50,14 @@ def test_func():
55
50
assert not [line for line in proc .stderr .splitlines ()
56
51
if "OpenGL" not in line ]
57
52
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
60
57
61
58
62
- @pytest .mark .backend ('TkAgg' , skip_on_importerror = True )
63
59
@_isolated_tk_test (success_count = 6 ) # len(bad_boxes)
64
- def test_blit (): # pragma: no cover
60
+ def test_blit ():
65
61
import matplotlib .pyplot as plt
66
62
import numpy as np
67
63
import matplotlib .backends .backend_tkagg # noqa
@@ -88,9 +84,8 @@ def test_blit(): # pragma: no cover
88
84
print ("success" )
89
85
90
86
91
- @pytest .mark .backend ('TkAgg' , skip_on_importerror = True )
92
87
@_isolated_tk_test (success_count = 1 )
93
- def test_figuremanager_preserves_host_mainloop (): # pragma: no cover
88
+ def test_figuremanager_preserves_host_mainloop ():
94
89
import tkinter
95
90
import matplotlib .pyplot as plt
96
91
success = []
@@ -116,10 +111,9 @@ def legitimate_quit():
116
111
@pytest .mark .skipif (platform .python_implementation () != 'CPython' ,
117
112
reason = 'PyPy does not support Tkinter threading: '
118
113
'https://foss.heptapod.net/pypy/pypy/-/issues/1929' )
119
- @pytest .mark .backend ('TkAgg' , skip_on_importerror = True )
120
114
@pytest .mark .flaky (reruns = 3 )
121
115
@_isolated_tk_test (success_count = 1 )
122
- def test_figuremanager_cleans_own_mainloop (): # pragma: no cover
116
+ def test_figuremanager_cleans_own_mainloop ():
123
117
import tkinter
124
118
import time
125
119
import matplotlib .pyplot as plt
@@ -144,10 +138,9 @@ def target():
144
138
thread .join ()
145
139
146
140
147
- @pytest .mark .backend ('TkAgg' , skip_on_importerror = True )
148
141
@pytest .mark .flaky (reruns = 3 )
149
142
@_isolated_tk_test (success_count = 0 )
150
- def test_never_update (): # pragma: no cover
143
+ def test_never_update ():
151
144
import tkinter
152
145
del tkinter .Misc .update
153
146
del tkinter .Misc .update_idletasks
@@ -171,9 +164,8 @@ def test_never_update(): # pragma: no cover
171
164
# checks them.
172
165
173
166
174
- @pytest .mark .backend ('TkAgg' , skip_on_importerror = True )
175
167
@_isolated_tk_test (success_count = 2 )
176
- def test_missing_back_button (): # pragma: no cover
168
+ def test_missing_back_button ():
177
169
import matplotlib .pyplot as plt
178
170
from matplotlib .backends .backend_tkagg import NavigationToolbar2Tk
179
171
0 commit comments