mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Update pytest-asyncio to 1.0.0 (#145988)
* Update pytest-asyncio to 1.0.0 * Remove event_loop fixture uses
This commit is contained in:
@ -19,7 +19,7 @@ pydantic==2.11.3
|
||||
pylint==3.3.7
|
||||
pylint-per-file-ignores==1.4.0
|
||||
pipdeptree==2.26.1
|
||||
pytest-asyncio==0.26.0
|
||||
pytest-asyncio==1.0.0
|
||||
pytest-aiohttp==1.1.0
|
||||
pytest-cov==6.0.0
|
||||
pytest-freezer==0.4.9
|
||||
|
@ -1,7 +1,5 @@
|
||||
"""Test configuration for auth."""
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.typing import ClientSessionGenerator
|
||||
@ -9,7 +7,6 @@ from tests.typing import ClientSessionGenerator
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_client(
|
||||
event_loop: AbstractEventLoop,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
socket_enabled: None,
|
||||
) -> ClientSessionGenerator:
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""The tests for the emulated Hue component."""
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
from collections.abc import Generator
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
@ -38,7 +37,6 @@ class MockTransport:
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_client(
|
||||
event_loop: AbstractEventLoop,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
socket_enabled: None,
|
||||
) -> ClientSessionGenerator:
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""The tests for Home Assistant frontend."""
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
from collections.abc import Generator
|
||||
from http import HTTPStatus
|
||||
from pathlib import Path
|
||||
@ -95,7 +94,6 @@ async def frontend_themes(hass: HomeAssistant) -> None:
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_client(
|
||||
event_loop: AbstractEventLoop,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
socket_enabled: None,
|
||||
) -> ClientSessionGenerator:
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""HomeKit session fixtures."""
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
import asyncio
|
||||
from collections.abc import Generator
|
||||
from contextlib import suppress
|
||||
import os
|
||||
@ -26,12 +26,13 @@ def iid_storage(hass: HomeAssistant) -> Generator[AccessoryIIDStorage]:
|
||||
|
||||
@pytest.fixture
|
||||
def run_driver(
|
||||
hass: HomeAssistant, event_loop: AbstractEventLoop, iid_storage: AccessoryIIDStorage
|
||||
hass: HomeAssistant, iid_storage: AccessoryIIDStorage
|
||||
) -> Generator[HomeDriver]:
|
||||
"""Return a custom AccessoryDriver instance for HomeKit accessory init.
|
||||
|
||||
This mock does not mock async_stop, so the driver will not be stopped
|
||||
"""
|
||||
event_loop = asyncio.get_event_loop()
|
||||
with (
|
||||
patch("pyhap.accessory_driver.AsyncZeroconf"),
|
||||
patch("pyhap.accessory_driver.AccessoryEncoder"),
|
||||
@ -55,9 +56,10 @@ def run_driver(
|
||||
|
||||
@pytest.fixture
|
||||
def hk_driver(
|
||||
hass: HomeAssistant, event_loop: AbstractEventLoop, iid_storage: AccessoryIIDStorage
|
||||
hass: HomeAssistant, iid_storage: AccessoryIIDStorage
|
||||
) -> Generator[HomeDriver]:
|
||||
"""Return a custom AccessoryDriver instance for HomeKit accessory init."""
|
||||
event_loop = asyncio.get_event_loop()
|
||||
with (
|
||||
patch("pyhap.accessory_driver.AsyncZeroconf"),
|
||||
patch("pyhap.accessory_driver.AccessoryEncoder"),
|
||||
@ -85,11 +87,11 @@ def hk_driver(
|
||||
@pytest.fixture
|
||||
def mock_hap(
|
||||
hass: HomeAssistant,
|
||||
event_loop: AbstractEventLoop,
|
||||
iid_storage: AccessoryIIDStorage,
|
||||
mock_zeroconf: MagicMock,
|
||||
) -> Generator[HomeDriver]:
|
||||
"""Return a custom AccessoryDriver instance for HomeKit accessory init."""
|
||||
event_loop = asyncio.get_event_loop()
|
||||
with (
|
||||
patch("pyhap.accessory_driver.AsyncZeroconf"),
|
||||
patch("pyhap.accessory_driver.AccessoryEncoder"),
|
||||
|
@ -1,7 +1,5 @@
|
||||
"""Test configuration for http."""
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.typing import ClientSessionGenerator
|
||||
@ -9,7 +7,6 @@ from tests.typing import ClientSessionGenerator
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_client(
|
||||
event_loop: AbstractEventLoop,
|
||||
aiohttp_client: ClientSessionGenerator,
|
||||
socket_enabled: None,
|
||||
) -> ClientSessionGenerator:
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""The tests for the image_processing component."""
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
from collections.abc import Callable
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
@ -26,7 +25,6 @@ async def setup_homeassistant(hass: HomeAssistant):
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_unused_port_factory(
|
||||
event_loop: AbstractEventLoop,
|
||||
unused_tcp_port_factory: Callable[[], int],
|
||||
socket_enabled: None,
|
||||
) -> Callable[[], int]:
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""Test the motionEye camera."""
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
from collections.abc import Callable
|
||||
import copy
|
||||
from unittest.mock import AsyncMock, Mock, call
|
||||
@ -67,7 +66,6 @@ from tests.common import async_fire_time_changed
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_server(
|
||||
event_loop: AbstractEventLoop,
|
||||
aiohttp_server: Callable[[], TestServer],
|
||||
socket_enabled: None,
|
||||
) -> Callable[[], TestServer]:
|
||||
|
@ -330,18 +330,18 @@ def long_repr_strings() -> Generator[None]:
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def enable_event_loop_debug(event_loop: asyncio.AbstractEventLoop) -> None:
|
||||
def enable_event_loop_debug() -> None:
|
||||
"""Enable event loop debug mode."""
|
||||
event_loop.set_debug(True)
|
||||
asyncio.get_event_loop().set_debug(True)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def verify_cleanup(
|
||||
event_loop: asyncio.AbstractEventLoop,
|
||||
expected_lingering_tasks: bool,
|
||||
expected_lingering_timers: bool,
|
||||
) -> Generator[None]:
|
||||
"""Verify that the test has cleaned up resources correctly."""
|
||||
event_loop = asyncio.get_event_loop()
|
||||
threads_before = frozenset(threading.enumerate())
|
||||
tasks_before = asyncio.all_tasks(event_loop)
|
||||
yield
|
||||
@ -492,9 +492,7 @@ def aiohttp_client_cls() -> type[CoalescingClient]:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def aiohttp_client(
|
||||
event_loop: asyncio.AbstractEventLoop,
|
||||
) -> Generator[ClientSessionGenerator]:
|
||||
def aiohttp_client() -> Generator[ClientSessionGenerator]:
|
||||
"""Override the default aiohttp_client since 3.x does not support aiohttp_client_cls.
|
||||
|
||||
Remove this when upgrading to 4.x as aiohttp_client_cls
|
||||
@ -504,7 +502,7 @@ def aiohttp_client(
|
||||
aiohttp_client(server, **kwargs)
|
||||
aiohttp_client(raw_server, **kwargs)
|
||||
"""
|
||||
loop = event_loop
|
||||
loop = asyncio.get_event_loop()
|
||||
clients = []
|
||||
|
||||
async def go(
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Test the auth script to manage local users."""
|
||||
|
||||
import argparse
|
||||
from asyncio import AbstractEventLoop
|
||||
import asyncio
|
||||
from collections.abc import Generator
|
||||
import logging
|
||||
from typing import Any
|
||||
@ -143,7 +143,7 @@ async def test_change_password_invalid_user(
|
||||
data.validate_login("invalid-user", "new-pass")
|
||||
|
||||
|
||||
def test_parsing_args(event_loop: AbstractEventLoop) -> None:
|
||||
async def test_parsing_args() -> None:
|
||||
"""Test we parse args correctly."""
|
||||
called = False
|
||||
|
||||
@ -158,7 +158,8 @@ def test_parsing_args(event_loop: AbstractEventLoop) -> None:
|
||||
|
||||
args = Mock(config="/somewhere/config", func=mock_func)
|
||||
|
||||
event_loop = asyncio.get_event_loop()
|
||||
with patch("argparse.ArgumentParser.parse_args", return_value=args):
|
||||
script_auth.run(None)
|
||||
await event_loop.run_in_executor(None, script_auth.run, None)
|
||||
|
||||
assert called, "Mock function did not get called"
|
||||
|
@ -55,7 +55,7 @@ def normalize_yaml_files(check_dict):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config_yaml", [BAD_CORE_CONFIG])
|
||||
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
|
||||
@pytest.mark.usefixtures("mock_is_file", "mock_hass_config_yaml")
|
||||
def test_bad_core_config() -> None:
|
||||
"""Test a bad core config setup."""
|
||||
res = check_config.check(get_test_config_dir())
|
||||
@ -65,7 +65,7 @@ def test_bad_core_config() -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config_yaml", [BASE_CONFIG + "light:\n platform: demo"])
|
||||
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
|
||||
@pytest.mark.usefixtures("mock_is_file", "mock_hass_config_yaml")
|
||||
def test_config_platform_valid() -> None:
|
||||
"""Test a valid platform setup."""
|
||||
res = check_config.check(get_test_config_dir())
|
||||
@ -96,7 +96,7 @@ def test_config_platform_valid() -> None:
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
|
||||
@pytest.mark.usefixtures("mock_is_file", "mock_hass_config_yaml")
|
||||
def test_component_platform_not_found(platforms: set[str], error: str) -> None:
|
||||
"""Test errors if component or platform not found."""
|
||||
# Make sure they don't exist
|
||||
@ -121,7 +121,7 @@ def test_component_platform_not_found(platforms: set[str], error: str) -> None:
|
||||
}
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
|
||||
@pytest.mark.usefixtures("mock_is_file", "mock_hass_config_yaml")
|
||||
def test_secrets() -> None:
|
||||
"""Test secrets config checking method."""
|
||||
res = check_config.check(get_test_config_dir(), True)
|
||||
@ -151,7 +151,7 @@ def test_secrets() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config_yaml", [BASE_CONFIG + ' packages:\n p1:\n group: ["a"]']
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
|
||||
@pytest.mark.usefixtures("mock_is_file", "mock_hass_config_yaml")
|
||||
def test_package_invalid() -> None:
|
||||
"""Test an invalid package."""
|
||||
res = check_config.check(get_test_config_dir())
|
||||
@ -168,7 +168,7 @@ def test_package_invalid() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config_yaml", [BASE_CONFIG + "automation: !include no.yaml"]
|
||||
)
|
||||
@pytest.mark.usefixtures("event_loop", "mock_hass_config_yaml")
|
||||
@pytest.mark.usefixtures("mock_hass_config_yaml")
|
||||
def test_bootstrap_error() -> None:
|
||||
"""Test a valid platform setup."""
|
||||
res = check_config.check(get_test_config_dir(YAML_CONFIG_FILE))
|
||||
|
Reference in New Issue
Block a user