code: def test_log_scalar_metric_with_run(ex):
      START = 10
      END = 100
      STEP_SIZE = 5
      messages = {}
  
      @ex.main
      def main_function(_run):
          # First, make sure the queue is empty:
          assert len(ex.current_run._metrics.get_last_metrics()) == 0
          for i in range(START, END, STEP_SIZE):
              val = i * i
              _run.log_scalar("training.loss", val, i)
          messages[
              "messages"
          ] = ex.current_run._metrics.get_last_metrics()
          """Calling get_last_metrics clears the metrics logger internal queue.
          If we don't call it here, it would be called during Sacred heartbeat 
          event after the run finishes, and the data we want to test would 
          be lost."""
  
      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 2 for calling a global function with example usage: test_log_scalar_metric_with_run(ex) without return types