code: def test_needs_reset(self):
      # 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, False, {}),
                  (("state", 3), 0, 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)]
      )
  
      # First Env: [1 2 (3_a) 5 6 (7_a)]
      # Second Env: [(1) (3_b) 5 6 (7_b)]
      # Results: (1), (3a), (3b), (7b)
      scores, lengths = evaluator.batch_run_evaluation_episodes(
          vec_env, agent, n_steps=None, n_episodes=4
      )
      assert len(scores) == 4
      assert len(lengths) == 4
      np.testing.assert_allclose(scores[0], 0)
      np.testing.assert_allclose(scores[1], 2)
      np.testing.assert_allclose(scores[2], 3)
      np.testing.assert_allclose(scores[3], 0.4)
      np.testing.assert_allclose(lengths[0], 3)
      np.testing.assert_allclose(lengths[1], 1)
      np.testing.assert_allclose(lengths[2], 1)
      np.testing.assert_allclose(lengths[3], 3)
      # 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 1 for calling the TestBatchRunEvaluationEpisode obj's underlying member method code with example usage: obj.test_needs_reset() and returns: env