def test_validate_all(tmpdir):
    """Assert custom message is being processed by validator."""
    tmpfile = tmpdir.join("settings.toml")
    tmpfile.write(TOML)

    settings = LazySettings(
        environments=True, SETTINGS_FILE_FOR_DYNACONF=str(tmpfile), silent=True
    )

    custom_msg = "You cannot set {name} to {value} in env {env}"
    settings.validators.register(
        Validator("MYSQL_HOST", eq="development.com", env="DEVELOPMENT"),
        Validator("MYSQL_HOST", ne="development.com", env="PRODUCTION"),
        Validator("VERSION", ne=1, messages={"operations": custom_msg}),
        Validator("BLABLABLA", must_exist=True),
    )

    with pytest.raises(ValidationError) as error:
        settings.validators.validate_all()

    assert (
        custom_msg.format(name="VERSION", value="1", env="DEVELOPMENT")
        in error.value.message
    )
    assert "BLABLABLA" in error.value.message

    assert error.type == ValidationError
    assert len(error.value.details) == 2
Assert custom message is being processed by validator.
tests/test_validators.py