input: Write a Python function to train and test a reinforcement learning agent using the PPO2 algorithm on a custom Gym environment. 
  assert isinstance(env, gym.Env)
  assert model is not None
  assert total_reward >= 0
output: import gym
  from stable_baselines3 import PPO
  
  def train_and_test_ppo(env, total_timesteps=10000, test_episodes=10):
      model = PPO('MlpPolicy', env, verbose=1)
      model.learn(total_timesteps=total_timesteps)
  
      total_reward = 0
      for episode in range(test_episodes):
          obs = env.reset()
          done = False
          episode_reward = 0
          while not done:
              action, _states = model.predict(obs)
              obs, reward, done, info = env.step(action)
              episode_reward += reward
          total_reward += episode_reward
      
      avg_reward = total_reward / test_episodes
      return model, avg_reward
  
  # Example usage:
  # env = gym.make('YourCustomEnv-v0')
  # model, avg_reward = train_and_test_ppo(env)