Files
Gymnasium/tests/envs/spec_list.py

62 lines
1.6 KiB
Python
Raw Normal View History

from gym import envs, logger
2022-05-24 08:47:51 -04:00
SKIP_MUJOCO_V3_WARNING_MESSAGE = (
"Cannot run mujoco test because mujoco-py is not installed"
2021-07-29 15:39:42 -04:00
)
2022-05-24 08:47:51 -04:00
skip_mujoco_v3 = False
try:
import mujoco_py # noqa:F401
except ImportError:
skip_mujoco_v3 = True
2021-07-29 02:26:34 +02:00
def should_skip_env_spec_for_tests(spec):
# We skip tests for envs that require dependencies or are otherwise
# troublesome to run frequently
2019-07-12 13:59:33 -04:00
ep = spec.entry_point
# Skip mujoco tests for pull request CI
2022-05-24 08:47:51 -04:00
if skip_mujoco_v3 and ep.startswith("gym.envs.mujoco"):
return True
try:
import gym.envs.atari # noqa:F401
except ImportError:
if ep.startswith("gym.envs.atari"):
return True
try:
import Box2D # noqa:F401
except ImportError:
2021-07-29 02:26:34 +02:00
if ep.startswith("gym.envs.box2d"):
return True
2021-07-29 02:26:34 +02:00
if (
"GoEnv" in ep
or "HexEnv" in ep
2021-07-29 15:39:42 -04:00
or (
ep.startswith("gym.envs.atari")
2021-07-29 15:39:42 -04:00
and not spec.id.startswith("Pong")
and not spec.id.startswith("Seaquest")
)
):
2022-01-11 18:12:05 +01:00
logger.warn(f"Skipping tests for env {ep}")
return True
return False
2021-07-29 02:26:34 +02:00
2022-05-24 08:47:51 -04:00
def skip_mujoco_py_env_for_test(spec):
ep = spec.entry_point
version = spec.version
if ep.startswith("gym.envs.mujoco") and version < 4:
return True
return False
2021-07-29 02:26:34 +02:00
spec_list = [
spec
for spec in sorted(envs.registry.values(), key=lambda x: x.id)
2021-07-29 02:26:34 +02:00
if spec.entry_point is not None and not should_skip_env_spec_for_tests(spec)
]
2022-05-24 08:47:51 -04:00
spec_list_no_mujoco_py = [
spec for spec in spec_list if not skip_mujoco_py_env_for_test(spec)
]