Move fixtures to decorators in core tests (#119675)

This commit is contained in:
epenet 2024-06-14 13:32:42 +02:00 committed by GitHub
parent b80f7185b2
commit 01be5d5f6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 80 additions and 109 deletions

View file

@ -106,9 +106,8 @@ async def test_helpers_wrapper(hass: HomeAssistant) -> None:
assert result == ["hello"]
async def test_custom_component_name(
hass: HomeAssistant, enable_custom_integrations: None
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_custom_component_name(hass: HomeAssistant) -> None:
"""Test the name attribute of custom components."""
with pytest.raises(loader.IntegrationNotFound):
await loader.async_get_integration(hass, "test_standalone")
@ -137,10 +136,9 @@ async def test_custom_component_name(
assert TEST == 5
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_log_warning_custom_component(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
enable_custom_integrations: None,
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test that we log a warning when loading a custom component."""
@ -151,10 +149,9 @@ async def test_log_warning_custom_component(
assert "We found a custom integration test " in caplog.text
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_custom_integration_version_not_valid(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
enable_custom_integrations: None,
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test that we log a warning when custom integrations have a invalid version."""
with pytest.raises(loader.IntegrationNotFound):
@ -180,10 +177,10 @@ async def test_custom_integration_version_not_valid(
loader.BlockedIntegration(AwesomeVersion("2.0.0"), "breaks Home Assistant"),
],
)
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_custom_integration_version_blocked(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
enable_custom_integrations: None,
blocked_versions,
) -> None:
"""Test that we log a warning when custom integrations have a blocked version."""
@ -207,10 +204,10 @@ async def test_custom_integration_version_blocked(
loader.BlockedIntegration(AwesomeVersion("1.0.0"), "breaks Home Assistant"),
],
)
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_custom_integration_version_not_blocked(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
enable_custom_integrations: None,
blocked_versions,
) -> None:
"""Test that we log a warning when custom integrations have a blocked version."""
@ -493,9 +490,8 @@ async def test_async_get_platforms_caches_failures_when_component_loaded(
assert integration.get_platform_cached("light") is None
async def test_get_integration_legacy(
hass: HomeAssistant, enable_custom_integrations: None
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_get_integration_legacy(hass: HomeAssistant) -> None:
"""Test resolving integration."""
integration = await loader.async_get_integration(hass, "test_embedded")
assert integration.get_component().DOMAIN == "test_embedded"
@ -503,9 +499,8 @@ async def test_get_integration_legacy(
assert integration.get_platform_cached("switch") is not None
async def test_get_integration_custom_component(
hass: HomeAssistant, enable_custom_integrations: None
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_get_integration_custom_component(hass: HomeAssistant) -> None:
"""Test resolving integration."""
integration = await loader.async_get_integration(hass, "test_package")
@ -802,9 +797,8 @@ def _get_test_integration_with_usb_matcher(hass, name, config_flow):
)
async def test_get_custom_components(
hass: HomeAssistant, enable_custom_integrations: None
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_get_custom_components(hass: HomeAssistant) -> None:
"""Verify that custom components are cached."""
test_1_integration = _get_test_integration(hass, "test_1", False)
test_2_integration = _get_test_integration(hass, "test_2", True)
@ -1000,9 +994,8 @@ async def test_get_mqtt(hass: HomeAssistant) -> None:
assert mqtt["test_2"] == ["test_2/discovery"]
async def test_import_platform_executor(
hass: HomeAssistant, enable_custom_integrations: None
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_import_platform_executor(hass: HomeAssistant) -> None:
"""Test import a platform in the executor."""
integration = await loader.async_get_integration(
hass, "test_package_loaded_executor"
@ -1342,10 +1335,9 @@ async def test_async_get_component_preloads_config_and_config_flow(
}
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_async_get_component_loads_loop_if_already_in_sys_modules(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
enable_custom_integrations: None,
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Verify async_get_component does not create an executor job if the module is already in sys.modules."""
integration = await loader.async_get_integration(
@ -1407,10 +1399,8 @@ async def test_async_get_component_loads_loop_if_already_in_sys_modules(
assert module is module_mock
async def test_async_get_component_concurrent_loads(
hass: HomeAssistant,
enable_custom_integrations: None,
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_async_get_component_concurrent_loads(hass: HomeAssistant) -> None:
"""Verify async_get_component waits if the first load if called again when still in progress."""
integration = await loader.async_get_integration(
hass, "test_package_loaded_executor"
@ -1720,9 +1710,8 @@ async def test_async_get_platform_raises_after_import_failure(
assert "loaded_executor=False" not in caplog.text
async def test_platforms_exists(
hass: HomeAssistant, enable_custom_integrations: None
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_platforms_exists(hass: HomeAssistant) -> None:
"""Test platforms_exists."""
original_os_listdir = os.listdir
@ -1778,10 +1767,9 @@ async def test_platforms_exists(
assert integration.platforms_are_loaded(["other"]) is False
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_async_get_platforms_loads_loop_if_already_in_sys_modules(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
enable_custom_integrations: None,
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Verify async_get_platforms does not create an executor job.
@ -1881,10 +1869,8 @@ async def test_async_get_platforms_loads_loop_if_already_in_sys_modules(
assert integration.get_platform_cached("light") is light_module_mock
async def test_async_get_platforms_concurrent_loads(
hass: HomeAssistant,
enable_custom_integrations: None,
) -> None:
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_async_get_platforms_concurrent_loads(hass: HomeAssistant) -> None:
"""Verify async_get_platforms waits if the first load if called again.
Case is for when when a second load is called
@ -1945,10 +1931,9 @@ async def test_async_get_platforms_concurrent_loads(
assert integration.get_platform_cached("button") is button_module_mock
@pytest.mark.usefixtures("enable_custom_integrations")
async def test_integration_warnings(
hass: HomeAssistant,
enable_custom_integrations: None,
caplog: pytest.LogCaptureFixture,
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test integration warnings."""
await loader.async_get_integration(hass, "test_package_loaded_loop")