code: def test_constrained_layout7():
      """Test for proper warning if fig not set in GridSpec"""
      with pytest.warns(
          UserWarning,
          match=(
              "There are no gridspecs with layoutgrids. "
              "Possibly did not call parent GridSpec with "
              'the "figure" keyword'
          ),
      ):
          fig = plt.figure(layout="constrained")
          gs = gridspec.GridSpec(1, 2)
          gsl = gridspec.GridSpecFromSubplotSpec(2, 2, gs[0])
          gsr = gridspec.GridSpecFromSubplotSpec(1, 2, gs[1])
          for gs in gsl:
              fig.add_subplot(gs)
          # need to trigger a draw to get warning
          fig.draw_without_rendering()
  
imports: import gc
  import numpy
  import pytest
  import matplotlib
  from matplotlib.testing.decorators import image_comparison
  import matplotlib.pyplot
  import matplotlib.transforms
  from matplotlib import gridspec, ticker
label_desc: Use image node_id 10 for calling a global function with example usage: test_constrained_layout7() without return types