@@ -571,7 +571,8 @@ def test_invalid_layouts():
571571
572572# test that layouts can be swapped if no colorbar:
573573fig ,ax = plt .subplots (layout = "constrained" )
574- fig .set_layout_engine ("tight" )
574+ with pytest .warns (UserWarning ):
575+ fig .set_layout_engine ("tight" )
575576assert isinstance (fig .get_layout_engine (),TightLayoutEngine )
576577fig .set_layout_engine ("constrained" )
577578assert isinstance (fig .get_layout_engine (),ConstrainedLayoutEngine )
@@ -581,7 +582,8 @@ def test_invalid_layouts():
581582pc = ax .pcolormesh (np .random .randn (2 ,2 ))
582583fig .colorbar (pc )
583584with pytest .raises (RuntimeError ,match = 'Colorbar layout of new layout' ):
584- fig .set_layout_engine ("tight" )
585+ with pytest .warns (UserWarning ):
586+ fig .set_layout_engine ("tight" )
585587fig .set_layout_engine ("none" )
586588with pytest .raises (RuntimeError ,match = 'Colorbar layout of new layout' ):
587589fig .set_layout_engine ("tight" )
@@ -598,6 +600,14 @@ def test_invalid_layouts():
598600fig .set_layout_engine ("constrained" )
599601
600602
603+ def test_layout_change_warning ():
604+ """Raise a warning when an existing layout manager is changed to tight."""
605+ for layout in ('constrained' ,'compressed' ):
606+ fig ,ax = plt .subplots (layout = layout )
607+ with pytest .warns (UserWarning ,match = 'The layout manager has been' ):
608+ plt .tight_layout ()
609+
610+
601611@check_figures_equal (extensions = ["png" ,"pdf" ])
602612def test_add_artist (fig_test ,fig_ref ):
603613fig_test .dpi = 100