diff --git a/pants-plugins/uses_services/exceptions.py b/pants-plugins/uses_services/exceptions.py index ba8becdb4d..09a2a63796 100644 --- a/pants-plugins/uses_services/exceptions.py +++ b/pants-plugins/uses_services/exceptions.py @@ -34,6 +34,8 @@ class ServiceSpecificMessages: service_start_cmd_generic: str + env_vars_hint: str = "" + class ServiceMissingError(Exception): """Error raised when a test uses a service but that service is missing.""" @@ -162,6 +164,9 @@ def generate( """ ) + if messages.env_vars_hint: + instructions += f"\n\n{messages.env_vars_hint}" + return cls( service=service, platform=platform, diff --git a/pants-plugins/uses_services/redis_rules.py b/pants-plugins/uses_services/redis_rules.py index 5863bb1aa3..b53f3bd4d7 100644 --- a/pants-plugins/uses_services/redis_rules.py +++ b/pants-plugins/uses_services/redis_rules.py @@ -143,13 +143,6 @@ async def redis_is_running( if is_running: return RedisIsRunning() - env_vars_hint = dedent( - """ - You can also export the ST2TESTS_REDIS_HOST and ST2TESTS_REDIS_PORT - env vars to automatically use any redis host, local or remote, - while running unit and integration tests. - """ - ) # redis is not running, so raise an error with instructions. raise ServiceMissingError.generate( platform=platform, @@ -162,21 +155,24 @@ async def redis_is_running( """\ sudo yum -y install redis # Don't forget to start redis. - """ - ) - + env_vars_hint, + ), service_start_cmd_deb="systemctl start redis", not_installed_clause_deb="this is one way to install it:", install_instructions_deb=dedent( """\ sudo apt-get install -y mongodb redis # Don't forget to start redis. - """ - ) - + env_vars_hint, + ), service_start_cmd_generic="systemctl start redis", + env_vars_hint=dedent( + """\ + You can also export the ST2TESTS_REDIS_HOST and ST2TESTS_REDIS_PORT + env vars to automatically use any redis host, local or remote, + while running unit and integration tests. + """ + ), ), )