Refactor fixture calling for BMW tests (#118708)

* Refactor BMW tests to use pytest.mark.usefixtures

* Fix freeze_time

---------

Co-authored-by: Richard <rikroe@users.noreply.github.com>
pull/118712/head
Richard Kroegel 2024-06-03 13:16:12 +02:00 committed by GitHub
parent 765114bead
commit ef7c7f1c05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 34 additions and 34 deletions

View File

@ -14,10 +14,10 @@ from homeassistant.exceptions import HomeAssistantError
from . import check_remote_service_call, setup_mocked_integration
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_entity_state_attrs(
hass: HomeAssistant,
bmw_fixture: respx.Router,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test button options and values."""
@ -57,9 +57,9 @@ async def test_service_call_success(
check_remote_service_call(bmw_fixture, remote_service)
@pytest.mark.usefixtures("bmw_fixture")
async def test_service_call_fail(
hass: HomeAssistant,
bmw_fixture: respx.Router,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test failed button press."""

View File

@ -5,7 +5,7 @@ from unittest.mock import patch
from bimmer_connected.models import MyBMWAPIError, MyBMWAuthError
from freezegun.api import FrozenDateTimeFactory
import respx
import pytest
from homeassistant.components.bmw_connected_drive import DOMAIN as BMW_DOMAIN
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant
@ -18,7 +18,8 @@ from . import FIXTURE_CONFIG_ENTRY
from tests.common import MockConfigEntry, async_fire_time_changed
async def test_update_success(hass: HomeAssistant, bmw_fixture: respx.Router) -> None:
@pytest.mark.usefixtures("bmw_fixture")
async def test_update_success(hass: HomeAssistant) -> None:
"""Test the reauth form."""
config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY)
config_entry.add_to_hass(hass)
@ -32,8 +33,10 @@ async def test_update_success(hass: HomeAssistant, bmw_fixture: respx.Router) ->
)
@pytest.mark.usefixtures("bmw_fixture")
async def test_update_failed(
hass: HomeAssistant, bmw_fixture: respx.Router, freezer: FrozenDateTimeFactory
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the reauth form."""
config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY)
@ -59,8 +62,10 @@ async def test_update_failed(
assert isinstance(coordinator.last_exception, UpdateFailed) is True
@pytest.mark.usefixtures("bmw_fixture")
async def test_update_reauth(
hass: HomeAssistant, bmw_fixture: respx.Router, freezer: FrozenDateTimeFactory
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the reauth form."""
config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY)
@ -96,10 +101,9 @@ async def test_update_reauth(
assert isinstance(coordinator.last_exception, ConfigEntryAuthFailed) is True
@pytest.mark.usefixtures("bmw_fixture")
async def test_init_reauth(
hass: HomeAssistant,
bmw_fixture: respx.Router,
freezer: FrozenDateTimeFactory,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the reauth form."""

View File

@ -19,11 +19,11 @@ from tests.typing import ClientSessionGenerator
@pytest.mark.freeze_time(datetime.datetime(2022, 7, 10, 11, tzinfo=datetime.UTC))
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_config_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
bmw_fixture,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test config entry diagnostics."""
@ -38,12 +38,12 @@ async def test_config_entry_diagnostics(
@pytest.mark.freeze_time(datetime.datetime(2022, 7, 10, 11, tzinfo=datetime.UTC))
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_device_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
device_registry: dr.DeviceRegistry,
bmw_fixture,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test device diagnostics."""
@ -63,12 +63,12 @@ async def test_device_diagnostics(
@pytest.mark.freeze_time(datetime.datetime(2022, 7, 10, 11, tzinfo=datetime.UTC))
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_device_diagnostics_vehicle_not_found(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
device_registry: dr.DeviceRegistry,
bmw_fixture,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test device diagnostics when the vehicle cannot be found."""

View File

@ -3,7 +3,6 @@
from unittest.mock import patch
import pytest
import respx
from homeassistant.components.bmw_connected_drive.const import DOMAIN as BMW_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
@ -137,10 +136,10 @@ async def test_dont_migrate_unique_ids(
assert entity_migrated != entity_not_changed
@pytest.mark.usefixtures("bmw_fixture")
async def test_remove_stale_devices(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
bmw_fixture: respx.Router,
) -> None:
"""Test remove stale device registry entries."""
mock_config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY)

View File

@ -14,10 +14,10 @@ from homeassistant.exceptions import HomeAssistantError
from . import check_remote_service_call, setup_mocked_integration
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_entity_state_attrs(
hass: HomeAssistant,
bmw_fixture: respx.Router,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test number options and values.."""
@ -62,6 +62,7 @@ async def test_service_call_success(
assert hass.states.get(entity_id).state == new_value
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.parametrize(
("entity_id", "value"),
[
@ -72,7 +73,6 @@ async def test_service_call_invalid_input(
hass: HomeAssistant,
entity_id: str,
value: str,
bmw_fixture: respx.Router,
) -> None:
"""Test not allowed values for number inputs."""
@ -92,6 +92,7 @@ async def test_service_call_invalid_input(
assert hass.states.get(entity_id).state == old_value
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.parametrize(
("raised", "expected"),
[
@ -104,7 +105,6 @@ async def test_service_call_fail(
hass: HomeAssistant,
raised: Exception,
expected: Exception,
bmw_fixture: respx.Router,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test exception handling."""

View File

@ -14,10 +14,10 @@ from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from . import check_remote_service_call, setup_mocked_integration
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_entity_state_attrs(
hass: HomeAssistant,
bmw_fixture: respx.Router,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test select options and values.."""
@ -74,6 +74,7 @@ async def test_service_call_success(
assert hass.states.get(entity_id).state == new_value
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.parametrize(
("entity_id", "value"),
[
@ -85,7 +86,6 @@ async def test_service_call_invalid_input(
hass: HomeAssistant,
entity_id: str,
value: str,
bmw_fixture: respx.Router,
) -> None:
"""Test not allowed values for select inputs."""
@ -105,6 +105,7 @@ async def test_service_call_invalid_input(
assert hass.states.get(entity_id).state == old_value
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.parametrize(
("raised", "expected"),
[
@ -117,7 +118,6 @@ async def test_service_call_fail(
hass: HomeAssistant,
raised: Exception,
expected: Exception,
bmw_fixture: respx.Router,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test exception handling."""

View File

@ -1,8 +1,6 @@
"""Test BMW sensors."""
from freezegun import freeze_time
import pytest
import respx
from syrupy.assertion import SnapshotAssertion
from homeassistant.core import HomeAssistant
@ -15,11 +13,11 @@ from homeassistant.util.unit_system import (
from . import setup_mocked_integration
@freeze_time("2023-06-22 10:30:00+00:00")
@pytest.mark.freeze_time("2023-06-22 10:30:00+00:00")
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_entity_state_attrs(
hass: HomeAssistant,
bmw_fixture: respx.Router,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test sensor options and values.."""
@ -31,6 +29,7 @@ async def test_entity_state_attrs(
assert hass.states.async_all("sensor") == snapshot
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.parametrize(
("entity_id", "unit_system", "value", "unit_of_measurement"),
[
@ -56,7 +55,6 @@ async def test_unit_conversion(
unit_system: UnitSystem,
value: str,
unit_of_measurement: str,
bmw_fixture,
) -> None:
"""Test conversion between metric and imperial units for sensors."""

View File

@ -14,10 +14,9 @@ from homeassistant.exceptions import HomeAssistantError
from . import check_remote_service_call, setup_mocked_integration
@pytest.mark.usefixtures("bmw_fixture")
async def test_entity_state_attrs(
hass: HomeAssistant,
bmw_fixture: respx.Router,
entity_registry_enabled_by_default: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test switch options and values.."""
@ -65,6 +64,7 @@ async def test_service_call_success(
assert hass.states.get(entity_id).state == new_value
@pytest.mark.usefixtures("bmw_fixture")
@pytest.mark.parametrize(
("raised", "expected"),
[
@ -77,7 +77,6 @@ async def test_service_call_fail(
hass: HomeAssistant,
raised: Exception,
expected: Exception,
bmw_fixture: respx.Router,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test exception handling."""