docstr: st.pyplot should clear the passed-in figure if `clear_figure` is True.
docstr_tok: ["st.pyplot","should","clear","the","passed-in","figure","if","`","clear_figure","`","is","True","."]
code: def test_st_pyplot_clear_figure(
      self, _, clear_figure: Optional[bool]
  ):
      """st.pyplot should clear the passed-in figure if `clear_figure` is True."""
      fig = plt.figure()
      ax1 = fig.add_subplot(111)
      ax1.hist(np.random.normal(1, 1, size=100), bins=20)
      with patch.object(
          fig, "clf", wraps=fig.clf, autospec=True
      ) as fig_clf:
          st.pyplot(fig, clear_figure=clear_figure)
  
          if clear_figure is True:
              fig_clf.assert_called_once()
          else:
              fig_clf.assert_not_called()
  
file_path: streamlit/lib/tests/streamlit/elements/pyplot_test.py
imports: from typing import Optional
  from unittest.mock import patch
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from parameterized import parameterized
  import streamlit
  from streamlit.elements import image
  from streamlit.web.server.server import MEDIA_ENDPOINT
  from tests.delta_generator_test_case import DeltaGeneratorTestCase
label_desc: Use image node_id 5 for calling the PyplotTest obj's underlying member method code with example usage: obj.test_st_pyplot_clear_figure(_, clear_figure) without return types