Skip to content

Commit 6086f95

Browse files
authored
build(config-test): dry run yaml examples test (#292)
1. Add config dry run sanity checks --------- Signed-off-by: Anna Warno <awarno@nvidia.com>
1 parent f34039c commit 6086f95

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

packages/nemo-evaluator-launcher/tests/unit_tests/conftest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,29 @@ class _ML:
469469
"nemo_evaluator_launcher.exporters.mlflow.mlflow", _ML, raising=True
470470
)
471471
return _ML, _RunCtx
472+
473+
474+
@pytest.fixture
475+
def setup_env_vars(monkeypatch):
476+
"""Mock environment variables for testing - returns dummy values for all env vars."""
477+
import os
478+
479+
# Create a dict that returns dummy values for any key
480+
class MockEnviron(dict):
481+
def __getitem__(self, key):
482+
try:
483+
return super().__getitem__(key)
484+
except KeyError:
485+
# Return dummy value for any missing key
486+
return "dummy_value_for_testing"
487+
488+
def get(self, key, default=None):
489+
try:
490+
return self[key]
491+
except KeyError:
492+
return default if default is not None else "dummy_value_for_testing"
493+
494+
# Copy current environment, ensuring all keys are strings
495+
current_env = {k: v for k, v in os.environ.items() if isinstance(k, str)}
496+
mock_env = MockEnviron(current_env)
497+
monkeypatch.setattr("os.environ", mock_env)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
"""Minimal tests for example configuration files with dry_run."""
17+
18+
import pathlib
19+
20+
import pytest
21+
from hydra.core.global_hydra import GlobalHydra
22+
23+
from nemo_evaluator_launcher.api.functional import RunConfig, run_eval
24+
25+
# Get the examples directory path
26+
EXAMPLES_DIR = (pathlib.Path(__file__).parent.parent.parent / "examples").absolute()
27+
28+
# Discover all YAML example files
29+
EXAMPLE_YAMLS = [f.stem for f in EXAMPLES_DIR.glob("*.yaml") if f.is_file()]
30+
31+
32+
class TestExampleConfigs:
33+
"""Test that all example configuration files can be initialized with dry_run."""
34+
35+
@pytest.mark.parametrize("config_name", EXAMPLE_YAMLS)
36+
def test_example_config_dry_run(self, config_name, mock_execdb, setup_env_vars):
37+
"""Test that example configs can be loaded and run in dry_run mode."""
38+
# Skip lepton configs with deployment (they try to create real endpoints even in dry_run)
39+
if (
40+
config_name.startswith("lepton_")
41+
and config_name != "lepton_none_llama_3_1_8b_instruct"
42+
):
43+
pytest.skip(
44+
"Lepton configs with deployment try to create endpoints even in dry_run mode"
45+
)
46+
47+
# Clear Hydra instance
48+
GlobalHydra.instance().clear()
49+
50+
try:
51+
# Build overrides: output_dir for all, plus slurm-specific overrides
52+
overrides = ["execution.output_dir=/tmp/test_output"]
53+
54+
# Add slurm-specific overrides for configs starting with "slurm_"
55+
if config_name.startswith("slurm_"):
56+
overrides.extend(
57+
[
58+
"++execution.type=slurm",
59+
"++execution.hostname=test-slurm-host",
60+
"++execution.account=test-account",
61+
]
62+
)
63+
64+
# Load configuration using RunConfig.from_hydra (same as CLI)
65+
cfg = RunConfig.from_hydra(
66+
config_name=config_name,
67+
hydra_overrides=overrides,
68+
config_dir=str(EXAMPLES_DIR),
69+
)
70+
71+
# Run with dry_run - should not raise
72+
invocation_id = run_eval(cfg, dry_run=True)
73+
assert invocation_id is not None
74+
assert len(invocation_id) == 16 # Standard invocation ID length
75+
finally:
76+
GlobalHydra.instance().clear()

0 commit comments

Comments
 (0)