@@ -50,7 +50,25 @@ def _fetch_models_from_service() -> dict:
5050
5151
5252def before_all (context : Context ) -> None :
53- """Run before and after the whole shooting match."""
53+ """Run before and after the whole shooting match.
54+
55+ Initialize global test environment before the test suite runs.
56+
57+ Sets context.deployment_mode from the E2E_DEPLOYMENT_MODE environment
58+ variable (default "server") and context.is_library_mode accordingly.
59+
60+ Attempts to detect a default LLM model and provider via
61+ _fetch_models_from_service() and stores results in context.default_model
62+ and context.default_provider; if detection fails, falls back to
63+ "gpt-4-turbo" and "openai".
64+
65+ Parameters:
66+ context (Context): Behave context into which this function writes:
67+ - deployment_mode (str): "server" or "library".
68+ - is_library_mode (bool): True when deployment_mode is "library".
69+ - default_model (str): Detected model id or fallback model.
70+ - default_provider (str): Detected provider id or fallback provider.
71+ """
5472 # Detect deployment mode from environment variable
5573 context .deployment_mode = os .getenv ("E2E_DEPLOYMENT_MODE" , "server" ).lower ()
5674 context .is_library_mode = context .deployment_mode == "library"
@@ -76,7 +94,18 @@ def before_all(context: Context) -> None:
7694
7795
7896def before_scenario (context : Context , scenario : Scenario ) -> None :
79- """Run before each scenario is run."""
97+ """Run before each scenario is run.
98+
99+ Prepare scenario execution by skipping scenarios based on tags and
100+ selecting a scenario-specific configuration.
101+
102+ Skips the scenario if it has the `skip` tag, if it has the `local` tag
103+ while the test run is not in local mode, or if it has
104+ `skip-in-library-mode` when running in library mode. When the scenario is
105+ tagged with `InvalidFeedbackStorageConfig` or `NoCacheConfig`, sets
106+ `context.scenario_config` to the appropriate configuration file path for
107+ the current deployment mode (library-mode or server-mode).
108+ """
80109 if "skip" in scenario .effective_tags :
81110 scenario .skip ("Marked with @skip" )
82111 return
@@ -100,7 +129,31 @@ def before_scenario(context: Context, scenario: Scenario) -> None:
100129
101130
102131def after_scenario (context : Context , scenario : Scenario ) -> None :
103- """Run after each scenario is run."""
132+ """Run after each scenario is run.
133+
134+ Perform per-scenario teardown: restore scenario-specific configuration and,
135+ in server mode, attempt to restart and verify the Llama Stack container if
136+ it was previously running.
137+
138+ If the scenario used an alternate feedback storage or no-cache
139+ configuration, the original feature configuration is restored and the
140+ lightspeed-stack container is restarted. When not running in library mode
141+ and the context indicates the Llama Stack was running before the scenario,
142+ this function attempts to start the llama-stack container and polls its
143+ health endpoint until it becomes healthy or a timeout is reached.
144+
145+ Parameters:
146+ context (Context): Behave test context. Expected attributes used here include:
147+ - feature_config: path to the feature-level configuration to restore.
148+ - is_library_mode (bool): whether tests run in library mode.
149+ - llama_stack_was_running (bool, optional): whether llama-stack was
150+ running before the scenario.
151+ - hostname_llama, port_llama (str/int, optional): host and port
152+ used for the llama-stack health check.
153+ scenario (Scenario): Behave scenario whose tags determine which
154+ scenario-specific teardown actions to run (e.g.,
155+ "InvalidFeedbackStorageConfig", "NoCacheConfig").
156+ """
104157 if "InvalidFeedbackStorageConfig" in scenario .effective_tags :
105158 switch_config (context .feature_config )
106159 restart_container ("lightspeed-stack" )
@@ -161,7 +214,10 @@ def after_scenario(context: Context, scenario: Scenario) -> None:
161214
162215
163216def before_feature (context : Context , feature : Feature ) -> None :
164- """Run before each feature file is exercised."""
217+ """Run before each feature file is exercised.
218+
219+ Prepare per-feature test environment and apply feature-specific configuration.
220+ """
165221 if "Authorized" in feature .tags :
166222 mode_dir = "library-mode" if context .is_library_mode else "server-mode"
167223 context .feature_config = (
@@ -178,7 +234,11 @@ def before_feature(context: Context, feature: Feature) -> None:
178234
179235
180236def after_feature (context : Context , feature : Feature ) -> None :
181- """Run after each feature file is exercised."""
237+ """Run after each feature file is exercised.
238+
239+ Perform feature-level teardown: restore any modified configuration and
240+ clean up feedback conversations.
241+ """
182242 if "Authorized" in feature .tags :
183243 switch_config (context .default_config_backup )
184244 restart_container ("lightspeed-stack" )
0 commit comments