diff --git a/tests/unit_tests/core/test_config.py b/tests/unit_tests/core/test_config.py index 372c1df7ee..55cc1f3027 100644 --- a/tests/unit_tests/core/test_config.py +++ b/tests/unit_tests/core/test_config.py @@ -28,13 +28,6 @@ def yaml_file(tmp_path: Path) -> Callable[[str], str]: return _yaml_file -@pytest.fixture(autouse=True) -def reset_core(): - """Reset CORE after each test.""" - yield - CORE.reset() - - def load_config_from_yaml( yaml_file: Callable[[str], str], yaml_content: str ) -> Config | None: @@ -61,7 +54,7 @@ def load_config_from_fixture( def test_validate_area_config_with_string() -> None: """Test that string area config is converted to structured format.""" - result: dict[str, Any] = validate_area_config("Living Room") + result = validate_area_config("Living Room") assert isinstance(result, dict) assert "id" in result @@ -80,7 +73,7 @@ def test_validate_area_config_with_dict() -> None: "name": "Test Area", } - result: dict[str, Any] = validate_area_config(input_config) + result = validate_area_config(input_config) assert result == input_config assert result["id"] == area_id diff --git a/tests/unit_tests/test_entity.py b/tests/unit_tests/test_entity.py index 3033b52a65..1b0c648be4 100644 --- a/tests/unit_tests/test_entity.py +++ b/tests/unit_tests/test_entity.py @@ -13,6 +13,9 @@ from esphome.cpp_generator import MockObj from esphome.entity import get_base_entity_object_id, setup_entity from esphome.helpers import sanitize, snake_case +# Pre-compiled regex pattern for extracting object IDs from expressions +OBJECT_ID_PATTERN = re.compile(r'\.set_object_id\(["\'](.*?)["\']\)') + @pytest.fixture(autouse=True) def restore_core_state() -> Generator[None, None, None]: @@ -256,7 +259,7 @@ def extract_object_id_from_expressions(expressions: list[str]) -> str | None: for expr in expressions: # Look for set_object_id calls with regex to handle various formats # Matches: var.set_object_id("temperature_2") or var.set_object_id('temperature_2') - match = re.search(r'\.set_object_id\(["\'](.*?)["\']\)', expr) + match = OBJECT_ID_PATTERN.search(expr) if match: return match.group(1) return None