22# License: BSD-3-Clause
33# Copyright the MNE-Python contributors.
44
5- import matplotlib .pyplot as plt
65import numpy as np
76import pytest
87from numpy .testing import assert_allclose , assert_equal
@@ -70,6 +69,10 @@ def test_dipolefit_gui_basic(renderer_interactive_pyvistaqt):
7069 assert len (g ._dipoles ) == len (g .dipoles ) == 2
7170 dip2 = g .dipoles [1 ]
7271
72+ # During tests, matplotlib does not open an actual window so we need to force the
73+ # close event.
74+ g ._fig_sensors .canvas .callbacks .process ("close_event" , None )
75+
7376 # The selected time of 0.09 is not actually in evoked.times, find the closest value
7477 # that is (0.08990784...). That should be the time recorded in the dipole object.
7578 closest_time = evoked .times [np .argmin (np .abs (evoked .times - g ._current_time ))]
@@ -100,9 +103,6 @@ def test_dipolefit_gui_basic(renderer_interactive_pyvistaqt):
100103 new_timecourses = np .vstack ((dip1_dict ["timecourse" ], dip2_dict ["timecourse" ]))
101104 assert not np .allclose (old_timecourses , new_timecourses , atol = 1e-10 )
102105
103- plt .close (g ._fig_sensors )
104- g ._fig ._renderer .close ()
105-
106106
107107@pytest .mark .slowtest
108108@testing .requires_testing_data
@@ -118,7 +118,6 @@ def test_dipolefit_gui_toggle_meshes(renderer_interactive_pyvistaqt):
118118 assert not g ._actors ["helmet" ].visibility
119119 with pytest .raises (ValueError , match = "Invalid value for the 'name' parameter" ):
120120 g .toggle_mesh ("non existent" )
121- g ._fig ._renderer .close ()
122121
123122
124123@pytest .mark .slowtest
@@ -170,7 +169,6 @@ def test_dipolefit_gui_dipole_controls(renderer_interactive_pyvistaqt):
170169 assert 2 in g ._dipoles
171170 assert list (g ._dipoles .keys ())[1 ] == 2
172171 assert list (g ._dipoles .values ())[1 ]["num" ] == 2 # new dipole number
173- g ._fig ._renderer .close ()
174172
175173
176174@pytest .mark .slowtest
@@ -194,4 +192,3 @@ def test_dipolefit_gui_save_load(tmpdir, renderer_interactive_pyvistaqt):
194192 assert_allclose (
195193 np .vstack ([d .pos for d in g .dipoles [4 :]]), dip_from_file .pos , atol = 0
196194 )
197- g ._fig ._renderer .close ()
0 commit comments