code: def test_automain_script_runs_main(ex):
      global __name__
      oldname = __name__
      main_called = [False]
  
      try:
          __name__ = "__main__"
          with patch.object(sys, "argv", ["test.py"]):
  
              @ex.automain
              def foo():
                  main_called[0] = True
  
              assert "foo" in ex.commands
              assert ex.commands["foo"] == foo
              assert ex.default_command == "foo"
              assert main_called[0] is True
      finally:
          __name__ = oldname
  
imports: from sacred import Ingredient
  from mock import patch
  import pytest
  import sys
  from sacred import cli_option
  from sacred import host_info_gatherer
  from sacred.experiment import Experiment
  from sacred.utils import apply_backspaces_and_linefeeds, ConfigAddedError, SacredError
label_desc: Use image node_id 4 for calling a global function with example usage: test_automain_script_runs_main(ex) without return types