code: def test_widget_added_removed():
      """
      Test that the value of a widget persists, disappears, and resets
      appropriately, as the widget is added and removed from the script execution.
      """
  
      def script():
          import streamlit as st
  
          cb = st.radio(
              "radio emulating a checkbox",
              options=["off", "on"],
              key="cb",
          )
          if cb == "on":
              st.radio(
                  "radio", options=["a", "b", "c"], key="conditional"
              )
  
      at = AppTest.from_function(script).run()
      assert len(at.radio) == 1
      with pytest.raises(KeyError):
          at.radio(key="conditional")
  
      at.radio(key="cb").set_value("on").run()
      assert len(at.radio) == 2
      assert at.radio(key="conditional").value == "a"
  
      at.radio(key="conditional").set_value("c").run()
      assert len(at.radio) == 2
      assert at.radio(key="conditional").value == "c"
  
      at.radio(key="cb").set_value("off").run()
      assert len(at.radio) == 1
      with pytest.raises(KeyError):
          at.radio(key="conditional")
  
      at.radio(key="cb").set_value("on").run()
      assert len(at.radio) == 2
      assert at.radio(key="conditional").value == "a"
  
file_path: streamlit/lib/tests/streamlit/testing/app_test_test.py
imports: import pytest
  from streamlit.testing.v1 import AppTest
label_desc: Use image node_id 9 for calling a global function with example usage: test_widget_added_removed() without return types