Coverage for mlos_bench/mlos_bench/tests/config/schedulers/conftest.py: 100%
12 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-14 00:55 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-14 00:55 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Pytest fixtures for Scheduler config tests.
8Provides fixtures for creating multiple TrialRunner instances using the mock environment
9config.
10"""
12from importlib.resources import files
14import pytest
16from mlos_bench.schedulers.trial_runner import TrialRunner
17from mlos_bench.services.config_persistence import ConfigPersistenceService
18from mlos_bench.util import path_join
20# pylint: disable=redefined-outer-name
22TRIAL_RUNNERS_COUNT = 4
25@pytest.fixture
26def mock_env_config_path() -> str:
27 """
28 Returns the absolute path to the mock environment configuration file.
30 This file is used to create TrialRunner instances for testing.
31 """
32 # Use the files() routine to locate the file relative to this directory
33 return path_join(
34 str(files("mlos_bench.config").joinpath("environments", "mock", "mock_env.jsonc")),
35 abs_path=True,
36 )
39@pytest.fixture
40def trial_runners(
41 config_loader_service: ConfigPersistenceService,
42 mock_env_config_path: str,
43) -> list[TrialRunner]:
44 """
45 Fixture that returns a list of TrialRunner instances using the mock environment
46 config.
48 Returns
49 -------
50 list[TrialRunner]
51 List of TrialRunner instances created from the mock environment config.
52 """
53 return TrialRunner.create_from_json(
54 config_loader=config_loader_service,
55 env_json=mock_env_config_path,
56 num_trial_runners=TRIAL_RUNNERS_COUNT,
57 )