Prevent tests changing units from affecting other tests (#70300)
* Prevent tests changing temperature_unit from affecting other tests * tweak
This commit is contained in:
parent
27c9e96865
commit
309424d3b9
9 changed files with 20 additions and 23 deletions
|
@ -30,7 +30,6 @@ from homeassistant.const import (
|
|||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from tests.common import async_fire_time_changed, load_fixture
|
||||
from tests.components.accuweather import init_integration
|
||||
|
@ -694,9 +693,8 @@ async def test_manual_update_entity(hass):
|
|||
assert mock_forecast.call_count == 1
|
||||
|
||||
|
||||
async def test_sensor_imperial_units(hass):
|
||||
async def test_sensor_imperial_units(hass, units_imperial):
|
||||
"""Test states of the sensor without forecast."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
await init_integration(hass)
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_ceiling")
|
||||
|
|
|
@ -4,6 +4,9 @@ from unittest.mock import AsyncMock, patch
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def patch_zeroconf_multiple_catcher():
|
||||
|
@ -33,3 +36,10 @@ def entity_registry_enabled_by_default() -> Generator[AsyncMock, None, None]:
|
|||
return_value=True,
|
||||
) as mock_entity_registry_enabled_by_default:
|
||||
yield mock_entity_registry_enabled_by_default
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def units_imperial(hass: HomeAssistant) -> Generator[None, None, None]:
|
||||
"""Fixture to temporary change units to imperial."""
|
||||
with patch.object(hass.config, "units", IMPERIAL_SYSTEM):
|
||||
yield
|
||||
|
|
|
@ -4,7 +4,6 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components import water_heater
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from tests.components.water_heater import common
|
||||
|
||||
|
@ -13,9 +12,8 @@ ENTITY_WATER_HEATER_CELSIUS = "water_heater.demo_water_heater_celsius"
|
|||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def setup_comp(hass):
|
||||
async def setup_comp(hass, units_imperial):
|
||||
"""Set up demo component."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
assert await async_setup_component(
|
||||
hass, water_heater.DOMAIN, {"water_heater": {"platform": "demo"}}
|
||||
)
|
||||
|
|
|
@ -34,7 +34,6 @@ from homeassistant.const import (
|
|||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.gdacs import _generate_mock_feed_entry
|
||||
|
@ -205,9 +204,8 @@ async def test_setup(hass):
|
|||
assert len(entity_registry.entities) == 1
|
||||
|
||||
|
||||
async def test_setup_imperial(hass):
|
||||
async def test_setup_imperial(hass, units_imperial):
|
||||
"""Test the setup of the integration using imperial unit system."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
# Set up some mock feed entries for this test.
|
||||
mock_entry_1 = _generate_mock_feed_entry(
|
||||
"1234",
|
||||
|
|
|
@ -28,7 +28,6 @@ from homeassistant.const import (
|
|||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.geonetnz_quakes import _generate_mock_feed_entry
|
||||
|
@ -168,9 +167,8 @@ async def test_setup(hass):
|
|||
assert len(entity_registry.entities) == 1
|
||||
|
||||
|
||||
async def test_setup_imperial(hass):
|
||||
async def test_setup_imperial(hass, units_imperial):
|
||||
"""Test the setup of the integration using imperial unit system."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
# Set up some mock feed entries for this test.
|
||||
mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 15.5, (38.0, -3.0))
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.geonetnz_volcano import _generate_mock_feed_entry
|
||||
|
@ -147,9 +146,8 @@ async def test_setup(hass):
|
|||
)
|
||||
|
||||
|
||||
async def test_setup_imperial(hass):
|
||||
async def test_setup_imperial(hass, units_imperial):
|
||||
"""Test the setup of the integration using imperial unit system."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
# Set up some mock feed entries for this test.
|
||||
mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 1, 15.5, (38.0, -3.0))
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ from homeassistant.const import (
|
|||
PRESSURE_PSI,
|
||||
)
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from . import init_integration
|
||||
|
||||
|
@ -126,10 +125,8 @@ async def test_sensors(hass):
|
|||
assert entry.unique_id == "JM000000000000000_rear_right_tire_pressure"
|
||||
|
||||
|
||||
async def test_sensors_imperial_units(hass):
|
||||
async def test_sensors_imperial_units(hass, units_imperial):
|
||||
"""Test that the sensors work properly with imperial units."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
|
||||
await init_integration(hass)
|
||||
|
||||
# Fuel Distance Remaining
|
||||
|
|
|
@ -10,7 +10,6 @@ from homeassistant.components.subaru.sensor import (
|
|||
SENSOR_TYPE,
|
||||
)
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from .api_responses import (
|
||||
EXPECTED_STATE_EV_IMPERIAL,
|
||||
|
@ -30,10 +29,8 @@ from tests.components.subaru.conftest import (
|
|||
VEHICLE_NAME = VEHICLE_DATA[TEST_VIN_2_EV][VEHICLE_NAME]
|
||||
|
||||
|
||||
async def test_sensors_ev_imperial(hass, ev_entry):
|
||||
async def test_sensors_ev_imperial(hass, ev_entry, units_imperial):
|
||||
"""Test sensors supporting imperial units."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
|
||||
with patch(MOCK_API_FETCH), patch(
|
||||
MOCK_API_GET_DATA, return_value=VEHICLE_STATUS_EV
|
||||
):
|
||||
|
|
|
@ -269,6 +269,7 @@ def hass(loop, load_registries, hass_storage, request):
|
|||
|
||||
exceptions = []
|
||||
hass = loop.run_until_complete(async_test_home_assistant(loop, load_registries))
|
||||
orig_units = hass.config.units
|
||||
orig_exception_handler = loop.get_exception_handler()
|
||||
loop.set_exception_handler(exc_handle)
|
||||
|
||||
|
@ -278,6 +279,8 @@ def hass(loop, load_registries, hass_storage, request):
|
|||
|
||||
# Restore timezone, it is set when creating the hass object
|
||||
dt_util.DEFAULT_TIME_ZONE = orig_tz
|
||||
# Restore the units as well
|
||||
hass.config.units = orig_units
|
||||
|
||||
for ex in exceptions:
|
||||
if (
|
||||
|
|
Loading…
Add table
Reference in a new issue