diff --git a/gymnasium/envs/registration.py b/gymnasium/envs/registration.py index 20d016b00..f76faa57c 100644 --- a/gymnasium/envs/registration.py +++ b/gymnasium/envs/registration.py @@ -161,7 +161,7 @@ def _check_can_jsonify(env_spec: dict[str, Any]): for key, value in env_spec.items(): if callable(value): - ValueError( + raise ValueError( f"Callable found in {spec_name} for {key} attribute with value={value}. Currently, Gymnasium does not support serialising callables." ) diff --git a/tests/envs/registration/test_spec.py b/tests/envs/registration/test_spec.py index 9ab52fc0b..bd01d2541 100644 --- a/tests/envs/registration/test_spec.py +++ b/tests/envs/registration/test_spec.py @@ -93,3 +93,18 @@ def test_spec_default_lookups(): assert gym.spec("test/TestEnv") is not None del gym.registry["test/TestEnv"] + + +def test_check_can_jsonify(): + def no_entry_point(): + pass + + gym.register(id="test/TestEnv-v0", entry_point=no_entry_point) + with pytest.raises( + ValueError, + match="^Callable found in test/TestEnv-v0 for entry_point attribute " + "with value=<.*>. Currently, Gymnasium does not support " + "serialising callables.$", + ): + gym.spec("test/TestEnv-v0").to_json() + del gym.registry["test/TestEnv-v0"]