code: def step_env_with_gym_quirks(
      env, spec, n=10, visualize=True, serialize_env=False
  ):
      """Step env helper.
  
      Args:
          env (Environment): Input environment.
          spec (EnvSpec): The environment specification.
          n (int): Steps.
          visualize (bool): Whether to visualize the environment.
          serialize_env (bool): Whether to serialize the environment.
  
      """
      if serialize_env:
          # Roundtrip serialization
          round_trip = cloudpickle.loads(cloudpickle.dumps(env))
          assert round_trip.spec == env.spec
          env = round_trip
  
      env.reset()
      for _ in range(n):
          es = env.step(env.action_space.sample())
          if visualize:
              if spec.id not in KNOWN_GYM_RENDER_NOT_IMPLEMENTED:
                  env.visualize()
              else:
                  with pytest.raises(NotImplementedError):
                      env.visualize()
          if es.last:
              break
  
      env.close()
  
file_path: garage/tests/helpers.py
imports: import cloudpickle
  import numpy
  import pytest
  from garage import Environment
  from tests.quirks import KNOWN_GYM_RENDER_NOT_IMPLEMENTED
label_desc: Use image node_id 2 for calling a global function with example usage: step_env_with_gym_quirks(env, spec, n, visualize, serialize_env) without return types