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:
Marc Mueller 2025-06-02 06:12:22 +02:00 committed by GitHub
parent dd85a1e5f0
commit 5e377b89fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 22 additions and 35 deletions

View File

@ -19,7 +19,7 @@ pydantic==2.11.3
pylint==3.3.7 pylint==3.3.7
pylint-per-file-ignores==1.4.0 pylint-per-file-ignores==1.4.0
pipdeptree==2.26.1 pipdeptree==2.26.1
pytest-asyncio==0.26.0 pytest-asyncio==1.0.0
pytest-aiohttp==1.1.0 pytest-aiohttp==1.1.0
pytest-cov==6.0.0 pytest-cov==6.0.0
pytest-freezer==0.4.9 pytest-freezer==0.4.9

View File

@ -1,7 +1,5 @@
"""Test configuration for auth.""" """Test configuration for auth."""
from asyncio import AbstractEventLoop
import pytest import pytest
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
@ -9,7 +7,6 @@ from tests.typing import ClientSessionGenerator
@pytest.fixture @pytest.fixture
def aiohttp_client( def aiohttp_client(
event_loop: AbstractEventLoop,
aiohttp_client: ClientSessionGenerator, aiohttp_client: ClientSessionGenerator,
socket_enabled: None, socket_enabled: None,
) -> ClientSessionGenerator: ) -> ClientSessionGenerator:

View File

@ -1,6 +1,5 @@
"""The tests for the emulated Hue component.""" """The tests for the emulated Hue component."""
from asyncio import AbstractEventLoop
from collections.abc import Generator from collections.abc import Generator
from http import HTTPStatus from http import HTTPStatus
import json import json
@ -38,7 +37,6 @@ class MockTransport:
@pytest.fixture @pytest.fixture
def aiohttp_client( def aiohttp_client(
event_loop: AbstractEventLoop,
aiohttp_client: ClientSessionGenerator, aiohttp_client: ClientSessionGenerator,
socket_enabled: None, socket_enabled: None,
) -> ClientSessionGenerator: ) -> ClientSessionGenerator:

View File

@ -1,6 +1,5 @@
"""The tests for Home Assistant frontend.""" """The tests for Home Assistant frontend."""
from asyncio import AbstractEventLoop
from collections.abc import Generator from collections.abc import Generator
from http import HTTPStatus from http import HTTPStatus
from pathlib import Path from pathlib import Path
@ -95,7 +94,6 @@ async def frontend_themes(hass: HomeAssistant) -> None:
@pytest.fixture @pytest.fixture
def aiohttp_client( def aiohttp_client(
event_loop: AbstractEventLoop,
aiohttp_client: ClientSessionGenerator, aiohttp_client: ClientSessionGenerator,
socket_enabled: None, socket_enabled: None,
) -> ClientSessionGenerator: ) -> ClientSessionGenerator:

View File

@ -1,6 +1,6 @@
"""HomeKit session fixtures.""" """HomeKit session fixtures."""
from asyncio import AbstractEventLoop import asyncio
from collections.abc import Generator from collections.abc import Generator
from contextlib import suppress from contextlib import suppress
import os import os
@ -26,12 +26,13 @@ def iid_storage(hass: HomeAssistant) -> Generator[AccessoryIIDStorage]:
@pytest.fixture @pytest.fixture
def run_driver( def run_driver(
hass: HomeAssistant, event_loop: AbstractEventLoop, iid_storage: AccessoryIIDStorage hass: HomeAssistant, iid_storage: AccessoryIIDStorage
) -> Generator[HomeDriver]: ) -> Generator[HomeDriver]:
"""Return a custom AccessoryDriver instance for HomeKit accessory init. """Return a custom AccessoryDriver instance for HomeKit accessory init.
This mock does not mock async_stop, so the driver will not be stopped This mock does not mock async_stop, so the driver will not be stopped
""" """
event_loop = asyncio.get_event_loop()
with ( with (
patch("pyhap.accessory_driver.AsyncZeroconf"), patch("pyhap.accessory_driver.AsyncZeroconf"),
patch("pyhap.accessory_driver.AccessoryEncoder"), patch("pyhap.accessory_driver.AccessoryEncoder"),
@ -55,9 +56,10 @@ def run_driver(
@pytest.fixture @pytest.fixture
def hk_driver( def hk_driver(
hass: HomeAssistant, event_loop: AbstractEventLoop, iid_storage: AccessoryIIDStorage hass: HomeAssistant, iid_storage: AccessoryIIDStorage
) -> Generator[HomeDriver]: ) -> Generator[HomeDriver]:
"""Return a custom AccessoryDriver instance for HomeKit accessory init.""" """Return a custom AccessoryDriver instance for HomeKit accessory init."""
event_loop = asyncio.get_event_loop()
with ( with (
patch("pyhap.accessory_driver.AsyncZeroconf"), patch("pyhap.accessory_driver.AsyncZeroconf"),
patch("pyhap.accessory_driver.AccessoryEncoder"), patch("pyhap.accessory_driver.AccessoryEncoder"),
@ -85,11 +87,11 @@ def hk_driver(
@pytest.fixture @pytest.fixture
def mock_hap( def mock_hap(
hass: HomeAssistant, hass: HomeAssistant,
event_loop: AbstractEventLoop,
iid_storage: AccessoryIIDStorage, iid_storage: AccessoryIIDStorage,
mock_zeroconf: MagicMock, mock_zeroconf: MagicMock,
) -> Generator[HomeDriver]: ) -> Generator[HomeDriver]:
"""Return a custom AccessoryDriver instance for HomeKit accessory init.""" """Return a custom AccessoryDriver instance for HomeKit accessory init."""
event_loop = asyncio.get_event_loop()
with ( with (
patch("pyhap.accessory_driver.AsyncZeroconf"), patch("pyhap.accessory_driver.AsyncZeroconf"),
patch("pyhap.accessory_driver.AccessoryEncoder"), patch("pyhap.accessory_driver.AccessoryEncoder"),

View File

@ -1,7 +1,5 @@
"""Test configuration for http.""" """Test configuration for http."""
from asyncio import AbstractEventLoop
import pytest import pytest
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
@ -9,7 +7,6 @@ from tests.typing import ClientSessionGenerator
@pytest.fixture @pytest.fixture
def aiohttp_client( def aiohttp_client(
event_loop: AbstractEventLoop,
aiohttp_client: ClientSessionGenerator, aiohttp_client: ClientSessionGenerator,
socket_enabled: None, socket_enabled: None,
) -> ClientSessionGenerator: ) -> ClientSessionGenerator:

View File

@ -1,6 +1,5 @@
"""The tests for the image_processing component.""" """The tests for the image_processing component."""
from asyncio import AbstractEventLoop
from collections.abc import Callable from collections.abc import Callable
from unittest.mock import PropertyMock, patch from unittest.mock import PropertyMock, patch
@ -26,7 +25,6 @@ async def setup_homeassistant(hass: HomeAssistant):
@pytest.fixture @pytest.fixture
def aiohttp_unused_port_factory( def aiohttp_unused_port_factory(
event_loop: AbstractEventLoop,
unused_tcp_port_factory: Callable[[], int], unused_tcp_port_factory: Callable[[], int],
socket_enabled: None, socket_enabled: None,
) -> Callable[[], int]: ) -> Callable[[], int]:

View File

@ -1,6 +1,5 @@
"""Test the motionEye camera.""" """Test the motionEye camera."""
from asyncio import AbstractEventLoop
from collections.abc import Callable from collections.abc import Callable
import copy import copy
from unittest.mock import AsyncMock, Mock, call from unittest.mock import AsyncMock, Mock, call
@ -67,7 +66,6 @@ from tests.common import async_fire_time_changed
@pytest.fixture @pytest.fixture
def aiohttp_server( def aiohttp_server(
event_loop: AbstractEventLoop,
aiohttp_server: Callable[[], TestServer], aiohttp_server: Callable[[], TestServer],
socket_enabled: None, socket_enabled: None,
) -> Callable[[], TestServer]: ) -> Callable[[], TestServer]:

View File

@ -330,18 +330,18 @@ def long_repr_strings() -> Generator[None]:
@pytest.fixture(autouse=True) @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.""" """Enable event loop debug mode."""
event_loop.set_debug(True) asyncio.get_event_loop().set_debug(True)
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def verify_cleanup( def verify_cleanup(
event_loop: asyncio.AbstractEventLoop,
expected_lingering_tasks: bool, expected_lingering_tasks: bool,
expected_lingering_timers: bool, expected_lingering_timers: bool,
) -> Generator[None]: ) -> Generator[None]:
"""Verify that the test has cleaned up resources correctly.""" """Verify that the test has cleaned up resources correctly."""
event_loop = asyncio.get_event_loop()
threads_before = frozenset(threading.enumerate()) threads_before = frozenset(threading.enumerate())
tasks_before = asyncio.all_tasks(event_loop) tasks_before = asyncio.all_tasks(event_loop)
yield yield
@ -492,9 +492,7 @@ def aiohttp_client_cls() -> type[CoalescingClient]:
@pytest.fixture @pytest.fixture
def aiohttp_client( def aiohttp_client() -> Generator[ClientSessionGenerator]:
event_loop: asyncio.AbstractEventLoop,
) -> Generator[ClientSessionGenerator]:
"""Override the default aiohttp_client since 3.x does not support aiohttp_client_cls. """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 Remove this when upgrading to 4.x as aiohttp_client_cls
@ -504,7 +502,7 @@ def aiohttp_client(
aiohttp_client(server, **kwargs) aiohttp_client(server, **kwargs)
aiohttp_client(raw_server, **kwargs) aiohttp_client(raw_server, **kwargs)
""" """
loop = event_loop loop = asyncio.get_event_loop()
clients = [] clients = []
async def go( async def go(

View File

@ -1,7 +1,7 @@
"""Test the auth script to manage local users.""" """Test the auth script to manage local users."""
import argparse import argparse
from asyncio import AbstractEventLoop import asyncio
from collections.abc import Generator from collections.abc import Generator
import logging import logging
from typing import Any from typing import Any
@ -143,7 +143,7 @@ async def test_change_password_invalid_user(
data.validate_login("invalid-user", "new-pass") 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.""" """Test we parse args correctly."""
called = False called = False
@ -158,7 +158,8 @@ def test_parsing_args(event_loop: AbstractEventLoop) -> None:
args = Mock(config="/somewhere/config", func=mock_func) args = Mock(config="/somewhere/config", func=mock_func)
event_loop = asyncio.get_event_loop()
with patch("argparse.ArgumentParser.parse_args", return_value=args): 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" assert called, "Mock function did not get called"

View File

@ -55,7 +55,7 @@ def normalize_yaml_files(check_dict):
@pytest.mark.parametrize("hass_config_yaml", [BAD_CORE_CONFIG]) @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: def test_bad_core_config() -> None:
"""Test a bad core config setup.""" """Test a bad core config setup."""
res = check_config.check(get_test_config_dir()) 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.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: def test_config_platform_valid() -> None:
"""Test a valid platform setup.""" """Test a valid platform setup."""
res = check_config.check(get_test_config_dir()) 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: def test_component_platform_not_found(platforms: set[str], error: str) -> None:
"""Test errors if component or platform not found.""" """Test errors if component or platform not found."""
# Make sure they don't exist # 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: def test_secrets() -> None:
"""Test secrets config checking method.""" """Test secrets config checking method."""
res = check_config.check(get_test_config_dir(), True) res = check_config.check(get_test_config_dir(), True)
@ -151,7 +151,7 @@ def test_secrets() -> None:
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hass_config_yaml", [BASE_CONFIG + ' packages:\n p1:\n group: ["a"]'] "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: def test_package_invalid() -> None:
"""Test an invalid package.""" """Test an invalid package."""
res = check_config.check(get_test_config_dir()) res = check_config.check(get_test_config_dir())
@ -168,7 +168,7 @@ def test_package_invalid() -> None:
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hass_config_yaml", [BASE_CONFIG + "automation: !include no.yaml"] "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: def test_bootstrap_error() -> None:
"""Test a valid platform setup.""" """Test a valid platform setup."""
res = check_config.check(get_test_config_dir(YAML_CONFIG_FILE)) res = check_config.check(get_test_config_dir(YAML_CONFIG_FILE))