diff --git a/tests/unit_tests/core/test_config.py b/tests/unit_tests/core/test_config.py index 35245b82d3..d31a66bdf6 100644 --- a/tests/unit_tests/core/test_config.py +++ b/tests/unit_tests/core/test_config.py @@ -3,10 +3,11 @@ from collections.abc import Callable from pathlib import Path from typing import Any +from unittest.mock import patch import pytest -from esphome import config, config_validation as cv +from esphome import config, config_validation as cv, yaml_util from esphome.config import Config from esphome.const import CONF_AREA, CONF_AREAS, CONF_DEVICES from esphome.core import CORE @@ -38,8 +39,15 @@ def load_config_from_yaml( yaml_file: Callable[[str], str], yaml_content: str ) -> Config | None: """Load configuration from YAML content.""" - CORE.config_path = yaml_file(yaml_content) - return config.read_config({}) + yaml_path = yaml_file(yaml_content) + parsed_yaml = yaml_util.load_yaml(yaml_path) + + # Mock yaml_util.load_yaml to return our parsed content + with ( + patch.object(yaml_util, "load_yaml", return_value=parsed_yaml), + patch.object(CORE, "config_path", yaml_path), + ): + return config.read_config({}) def load_config_from_fixture(