code: def test_log_scalar_metric_with_ex(ex):
      messages = {}
      START = 10
      END = 100
      STEP_SIZE = 5
  
      @ex.main
      def main_function(_run):
          for i in range(START, END, STEP_SIZE):
              val = i * i
              ex.log_scalar("training.loss", val, i)
          messages[
              "messages"
          ] = ex.current_run._metrics.get_last_metrics()
  
      ex.run()
      assert ex.current_run is not None
      messages = messages["messages"]
      assert len(messages) == (END - START) / STEP_SIZE
      for i in range(len(messages) - 1):
          assert messages[i].step < messages[i + 1].step
          assert messages[i].step == START + i * STEP_SIZE
          assert messages[i].timestamp <= messages[i + 1].timestamp
  
file_path: sacred/tests/test_metrics_logger.py
imports: import datetime
  import pytest
  from sacred import Experiment
  from sacred.metrics_logger import ScalarMetricLogEntry, linearize_metrics
label_desc: Use image node_id 3 for calling a global function with example usage: test_log_scalar_metric_with_ex(ex) without return types