code: def test_clear_and_catch_warnings():
      warnings.simplefilter("default", category=UserWarning)
      # Initial state of module, no warnings
      my_mod = sys.modules[__name__]
      try:
          my_mod.__warningregistry__.clear()
      except AttributeError:
          pass
  
      npt.assert_equal(getattr(my_mod, "__warningregistry__", {}), {})
      with dt.clear_and_catch_warnings(modules=[my_mod]):
          warnings.simplefilter("ignore")
          warnings.warn("Some warning")
      npt.assert_equal(my_mod.__warningregistry__, {})
      # Without specified modules, don't clear warnings during context
      with dt.clear_and_catch_warnings():
          warnings.warn("Some warning")
      assert_warn_len_equal(my_mod, 1)
      # Confirm that specifying module keeps old warning, does not add new
      with dt.clear_and_catch_warnings(modules=[my_mod]):
          warnings.warn("Another warning")
      assert_warn_len_equal(my_mod, 1)
      # Another warning, no module spec does add to warnings dict, except on
      # Python 3 (see comments in `assert_warn_len_equal`)
      with dt.clear_and_catch_warnings():
          warnings.warn("Another warning")
      assert_warn_len_equal(my_mod, 2)
      warnings.simplefilter("always", category=UserWarning)
  
file_path: dipy/dipy/testing/tests/test_testing.py
imports: import sys
  import warnings
  import numpy
  import dipy.testing
  import numpy.testing
label_desc: Use image node_id 3 for calling a global function with example usage: test_clear_and_catch_warnings() without return types