From d7fc282d8721f77f7b1e1ca0b2a0e30fccb3b858 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 10 Jul 2025 09:52:10 +0000 Subject: [PATCH] Improve tests --- tests/helpers/test_deprecation.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/helpers/test_deprecation.py b/tests/helpers/test_deprecation.py index 4a5d4b8d685..0298526132b 100644 --- a/tests/helpers/test_deprecation.py +++ b/tests/helpers/test_deprecation.py @@ -641,6 +641,14 @@ def test_enum_with_deprecated_members_integration_not_found( assert len(caplog.record_tuples) == 0 +@pytest.mark.parametrize( + "positional_arguments", + [ + [], + ["first_arg"], + ["first_arg", "second_arg"], + ], +) @pytest.mark.parametrize( ("breaks_in_ha_version", "extra_msg"), [ @@ -651,6 +659,7 @@ def test_enum_with_deprecated_members_integration_not_found( def test_deprecated_hass_binding( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, + positional_arguments: list[str], breaks_in_ha_version: str | None, extra_msg: str, ) -> None: @@ -659,10 +668,10 @@ def test_deprecated_hass_binding( calls = [] @deprecated_hass_binding(breaks_in_ha_version=breaks_in_ha_version) - def mock_deprecated_function(): - calls.append("called") + def mock_deprecated_function(*args: str) -> None: + calls.append(args) - mock_deprecated_function() + mock_deprecated_function(*positional_arguments) assert ( "The deprecated argument hass was passed to mock_deprecated_function." f"{extra_msg}" @@ -670,10 +679,14 @@ def test_deprecated_hass_binding( ) not in caplog.text assert len(calls) == 1 - mock_deprecated_function(hass) + mock_deprecated_function(hass, *positional_arguments) assert ( "The deprecated argument hass was passed to mock_deprecated_function." f"{extra_msg}" " Use mock_deprecated_function without hass argument instead" ) in caplog.text assert len(calls) == 2 + + # Ensure that the two calls are the same, as the second call should have been + # modified to remove the hass argument. + assert calls[0] == calls[1]