@@ -116,9 +116,9 @@ class Compose:
116116 """
117117
118118 # The docker-compose command (for the first test)
119- _COMPOSE_COMMAND : Optional [ str ] = None
119+ _COMPOSE_COMMAND : str = ""
120120 # The docker-compose version (for the first test)
121- _COMPOSE_VERSION : Optional [ str ] = None
121+ _COMPOSE_VERSION : str = ""
122122
123123 def __init__ (
124124 self ,
@@ -158,14 +158,7 @@ def __init__(
158158 self ._user_id : Optional [int ] = user_id
159159 self ._group_id : Optional [int ] = group_id
160160
161- # Do we have the 'docker compose' command?
162- if not Compose ._COMPOSE_COMMAND :
163- Compose ._COMPOSE_COMMAND = _get_docker_compose_command ()
164- print (f"# Compose command: { Compose ._COMPOSE_COMMAND } " )
165- # Do we have the 'docker-compose' command?
166- if not Compose ._COMPOSE_VERSION :
167- Compose ._COMPOSE_VERSION = _get_docker_compose_version ()
168- print (f"# Compose version: { Compose ._COMPOSE_VERSION } " )
161+ assert Compose .try_to_set_compose_command ()
169162
170163 def get_test_path (self ) -> str :
171164 """Returns the path to the root directory for a given test."""
@@ -248,7 +241,7 @@ def run(
248241 caller along with the stdout and stderr content.
249242 A non-zero exit code does not necessarily mean the test has failed.
250243 """
251- assert Compose ._COMPOSE_COMMAND
244+ assert Compose .try_to_set_compose_command ()
252245
253246 execution_directory : str = self .get_test_path ()
254247
@@ -323,14 +316,31 @@ def delete(self) -> None:
323316
324317 print ("# Compose: Deleted" )
325318
319+ @staticmethod
320+ def try_to_set_compose_command () -> bool :
321+ """Tries to find the docker-compose command,
322+ setting Compose._COMPOSE_COMMAND when found"""
323+ # Do we have the 'docker compose' command?
324+ if not Compose ._COMPOSE_COMMAND :
325+ Compose ._COMPOSE_COMMAND = _get_docker_compose_command ()
326+ print (f"# Compose command: { Compose ._COMPOSE_COMMAND } " )
327+ # Do we have the 'docker-compose' command?
328+ if not Compose ._COMPOSE_VERSION :
329+ Compose ._COMPOSE_VERSION = _get_docker_compose_version ()
330+ print (f"# Compose version: { Compose ._COMPOSE_VERSION } " )
331+
332+ if Compose ._COMPOSE_COMMAND and Compose ._COMPOSE_VERSION :
333+ return True
334+ return False
335+
326336 @staticmethod
327337 def run_group_compose_file (compose_file : str , delay_seconds : int = 0 ) -> bool :
328338 """Starts a group compose file in a detached state.
329339 The file is expected to be a compose file in the 'data-manager' directory.
330340 We pull the container image to reduce the 'docker-compose up' time
331341 and then optionally wait for a period of seconds.
332342 """
333- assert Compose ._COMPOSE_COMMAND
343+ assert Compose .try_to_set_compose_command ()
334344
335345 print ("# Compose: Starting test group containers..." )
336346
@@ -384,7 +394,7 @@ def stop_group_compose_file(compose_file: str) -> bool:
384394 """Stops a group compose file.
385395 The file is expected to be a compose file in the 'data-manager' directory.
386396 """
387- assert Compose ._COMPOSE_COMMAND
397+ assert Compose .try_to_set_compose_command ()
388398
389399 print ("# Compose: Stopping test group containers..." )
390400
0 commit comments