@@ -1262,7 +1262,6 @@ def use(backend, warn=False, force=True):
12621262 If True and not *force*, warn that the call will have no effect if
12631263 this is called after pyplot has been imported and a backend is set up.
12641264
1265-
12661265 force : bool, optional, default: True
12671266 If True, attempt to switch the backend. An ImportError is raised if
12681267 an interactive backend is selected, but another interactive
@@ -1281,20 +1280,17 @@ def use(backend, warn=False, force=True):
12811280 elif 'matplotlib.pyplot' in sys .modules :
12821281 # pyplot has already been imported (which triggered backend selection)
12831282 # and the requested backend is different from the current one.
1284-
1285- # If we are going to force the switch, never warn, else, if warn
1286- # is True, then direct users to `plt.switch_backend`
1287- if (not force ) and warn :
1288- cbook ._warn_external (
1289- "matplotlib.pyplot has already been imported, "
1290- "this call will have no effect." )
1291-
1292- # if we are going to force switching the backend, pull in
1293- # `switch_backend` from pyplot. This will only happen if
1294- # pyplot is already imported.
12951283 if force :
1284+ # if we are going to force switching the backend, pull in
1285+ # `switch_backend` from pyplot (which is already imported).
12961286 from matplotlib .pyplot import switch_backend
12971287 switch_backend (name )
1288+ elif warn :
1289+ # Only if we are not going to force the switch *and* warn is True,
1290+ # then direct users to `plt.switch_backend`.
1291+ cbook ._warn_external (
1292+ "matplotlib.pyplot has already been imported, "
1293+ "this call will have no effect." )
12981294 else :
12991295 # Finally if pyplot is not imported update both rcParams and
13001296 # rcDefaults so restoring the defaults later with rcdefaults
@@ -1385,6 +1381,7 @@ def _init_tests():
13851381 raise
13861382
13871383
1384+ @cbook ._delete_parameter ("3.2" , "switch_backend_warn" )
13881385def test (verbosity = None , coverage = False , switch_backend_warn = True ,
13891386 recursionlimit = 0 , ** kwargs ):
13901387 """Run the matplotlib test suite."""
@@ -1426,7 +1423,7 @@ def test(verbosity=None, coverage=False, switch_backend_warn=True,
14261423 retcode = pytest .main (args , ** kwargs )
14271424 finally :
14281425 if old_backend .lower () != 'agg' :
1429- use (old_backend , warn = switch_backend_warn )
1426+ use (old_backend )
14301427 if recursionlimit :
14311428 sys .setrecursionlimit (old_recursionlimit )
14321429
0 commit comments