code: def test_batch_run_evaluation_episodes_with_n_steps(
      n_episodes, n_steps
  ):
      # MagicMock can mock eval_mode while Mock cannot
      agent = mock.MagicMock()
      agent.batch_act.side_effect = [[1, 1]] * 5
  
      def make_env(idx):
          env = mock.Mock()
          if idx == 0:
              # First episode: 0 -> 1 -> 2 -> 3 (reset)
              # Second episode: 4 -> 5 -> 6 -> 7 (done)
              env.reset.side_effect = [("state", 0), ("state", 4)]
              env.step.side_effect = [
                  (("state", 1), 0, False, {}),
                  (("state", 2), 0.1, False, {}),
                  (("state", 3), 0.2, False, {"needs_reset": True}),
                  (("state", 5), -0.5, False, {}),
                  (("state", 6), 0, False, {}),
                  (("state", 7), 1, True, {}),
              ]
          else:
              # First episode: 0 -> 1 (reset)
              # Second episode: 2 -> 3 (reset)
              # Third episode: 4 -> 5 -> 6 -> 7 (done)
              env.reset.side_effect = [
                  ("state", 0),
                  ("state", 2),
                  ("state", 4),
              ]
              env.step.side_effect = [
                  (("state", 1), 2, False, {"needs_reset": True}),
                  (("state", 3), 3, False, {"needs_reset": True}),
                  (("state", 5), -0.6, False, {}),
                  (("state", 6), 0, False, {}),
                  (("state", 7), 1, True, {}),
              ]
          return env
  
      vec_env = pfrl.envs.SerialVectorEnv(
          [make_env(i) for i in range(2)]
      )
      if n_episodes:
          with pytest.raises(AssertionError):
              scores, lengths = evaluator.batch_run_evaluation_episodes(
                  vec_env, agent, n_steps=n_steps, n_episodes=n_episodes
              )
      else:
          # First Env:  [1   2   (3_a)  5  6   (7_a)]
          # Second Env: [(1)(3_b) 5     6 (7_b)]
          scores, lengths = evaluator.batch_run_evaluation_episodes(
              vec_env, agent, n_steps=n_steps, n_episodes=n_episodes
          )
          if n_steps == 2:
              assert len(scores) == 1
              assert len(lengths) == 1
              np.testing.assert_allclose(scores[0], 0.1)
              np.testing.assert_allclose(lengths[0], 2)
              assert agent.batch_observe.call_count == 2
          else:
              assert len(scores) == 3
              assert len(lengths) == 3
              np.testing.assert_allclose(scores[0], 0.3)
              np.testing.assert_allclose(scores[1], 2.0)
              np.testing.assert_allclose(scores[2], 3.0)
              np.testing.assert_allclose(lengths[0], 3)
              np.testing.assert_allclose(lengths[1], 1)
              np.testing.assert_allclose(lengths[2], 1)
          # batch_reset should be all True
          assert all(agent.batch_observe.call_args[0][3])
  
file_path: pfrl/tests/experiments_tests/test_evaluator.py
imports: import tempfile
  import unittest
  from unittest import mock
  import numpy
  import pytest
  import pfrl
  from pfrl.experiments import evaluator
label_desc: Use image node_id 4 for calling a global function with example usage: test_batch_run_evaluation_episodes_with_n_steps(n_episodes, n_steps) and returns: env