-
-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
General information
Home Assistant
Version:
Installation method (according to instructions):
[x] N/A
Integration
Installation method:
[ ] HACS
[ ] manual from release
[x] manual from git
Integration version: v2.3.2
How it works now?
Currently 3 pytest test-cases fail, and all fail if pytest --asyncio-mode=auto is not used. (See also: MatthewFlamm/pytest-homeassistant-custom-component#158)
Two of the test cases fail with AttributeError: module 'homeassistant.data_entry_flow' has no attribute 'RESULT_TYPE_FORM', which is to be expected as RESULT_TYPE_FORM was removed, see here
What do you expect?
Tests should work or be removed
Steps to reproduce
- Clone latest repo at v2.3.2
- Install deps
pytest --asyncio-mode=auto
Debug log
Tail of the pytest output
======================================================== short test summary info ========================================================
FAILED tests/functional/test_config_flow.py::test_successful_config_flow - AttributeError: module 'homeassistant.data_entry_flow' has no attribute 'RESULT_TYPE_FORM'
FAILED tests/functional/test_config_flow.py::test_options_flow - AttributeError: module 'homeassistant.data_entry_flow' has no attribute 'RESULT_TYPE_FORM'
FAILED tests/unit/test_instance.py::TestAsyncSleepAsAndroidInstance::test_async_setup_entry - TypeError: object MagicMock can't be used in 'await' expression
ERROR tests/functional/test_config_flow.py::test_successful_config_flow - Failed: Lingering timer after test <TimerHandle when=124021.060323025 MQTT._async_start_misc_periodic.<locals>._async_misc() at /nix...
ERROR tests/functional/test_config_flow.py::test_options_flow - Failed: Lingering timer after test <TimerHandle when=124021.232209314 MQTT._async_start_misc_periodic.<locals>._async_misc() at /nix...
=========================================== 3 failed, 20 passed, 1 warning, 2 errors in 1.70s ===========================================
Full log
/nix/store/yxmx0r8h1nha05gb0mnz6qky95fy8hdw-python3.13-pytest-asyncio-0.25.2/lib/python3.13/site-packages/pytest_asyncio/plugin.py:207: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"
warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
========================================================== test session starts ==========================================================
platform linux -- Python 3.13.2, pytest-8.3.4, pluggy-1.5.0
rootdir: /tmp/hi/HA-SleepAsAndroid
plugins: homeassistant-custom-component-0.13.222, anyio-4.8.0, asyncio-0.25.2, socket-0.7.0, requests-mock-1.12.1, respx-0.22.0, syrupy-4.8.2
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=None
collected 23 items
tests/functional/test_config_flow.py FEFE. [ 13%]
tests/unit/test_instance.py ...................F [100%]
================================================================ ERRORS =================================================================
___________________________________________ ERROR at teardown of test_successful_config_flow ____________________________________________
event_loop = <_UnixSelectorEventLoop running=False closed=True debug=True>, expected_lingering_tasks = False
expected_lingering_timers = False
@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."""
threads_before = frozenset(threading.enumerate())
tasks_before = asyncio.all_tasks(event_loop)
yield
event_loop.run_until_complete(event_loop.shutdown_default_executor())
if len(INSTANCES) >= 2:
count = len(INSTANCES)
for inst in INSTANCES:
inst.stop()
pytest.exit(f"Detected non stopped instances ({count}), aborting test run")
# Warn and clean-up lingering tasks and timers
# before moving on to the next test.
tasks = asyncio.all_tasks(event_loop) - tasks_before
for task in tasks:
if expected_lingering_tasks:
_LOGGER.warning("Lingering task after test %r", task)
else:
pytest.fail(f"Lingering task after test {task!r}")
task.cancel()
if tasks:
event_loop.run_until_complete(asyncio.wait(tasks))
for handle in get_scheduled_timer_handles(event_loop):
if not handle.cancelled():
with long_repr_strings():
if expected_lingering_timers:
_LOGGER.warning("Lingering timer after test %r", handle)
elif handle._args and isinstance(job := handle._args[-1], HassJob):
if job.cancel_on_shutdown:
continue
pytest.fail(f"Lingering timer after job {job!r}")
else:
> pytest.fail(f"Lingering timer after test {handle!r}")
E Failed: Lingering timer after test <TimerHandle when=124326.277909531 MQTT._async_start_misc_periodic.<locals>._async_misc() at /nix/store/gby5nizq77v05zrr656bq8ka2bv08j7z-homeassistant-2025.3.1/lib/python3.13/site-packages/homeassistant/components/mqtt/client.py:530 created at /nix/store/gby5nizq77v05zrr656bq8ka2bv08j7z-homeassistant-2025.3.1/lib/python3.13/site-packages/homeassistant/components/mqtt/client.py:536>
/nix/store/c3hj3yba8rbnrdiscl24r2qwymbsgz8p-python3.13-pytest-homeassistant-custom-component-0.13.222/lib/python3.13/site-packages/pytest_homeassistant_custom_component/plugins.py:407: Failed
--------------------------------------------------------- Captured stderr setup ---------------------------------------------------------
INFO:homeassistant.loader:Loaded sleep_as_android from custom_components.sleep_as_android
WARNING:homeassistant.loader:We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO:homeassistant.loader:Loaded mqtt from homeassistant.components.mqtt
INFO:homeassistant.loader:Loaded file_upload from homeassistant.components.file_upload
INFO:homeassistant.loader:Loaded http from homeassistant.components.http
INFO:homeassistant.setup:Setting up http
WARNING:aiohttp_fast_zlib:zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO:homeassistant.setup:Setting up file_upload
INFO:homeassistant.setup:Setting up mqtt
---------------------------------------------------------- Captured log setup -----------------------------------------------------------
INFO homeassistant.loader:loader.py:773 Loaded sleep_as_android from custom_components.sleep_as_android
WARNING homeassistant.loader:loader.py:687 We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO homeassistant.loader:loader.py:773 Loaded mqtt from homeassistant.components.mqtt
INFO homeassistant.loader:loader.py:773 Loaded file_upload from homeassistant.components.file_upload
INFO homeassistant.loader:loader.py:773 Loaded http from homeassistant.components.http
INFO homeassistant.setup:setup.py:390 Setting up http
WARNING aiohttp_fast_zlib:__init__.py:49 zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO homeassistant.setup:setup.py:390 Setting up file_upload
INFO homeassistant.setup:setup.py:390 Setting up mqtt
________________________________________________ ERROR at teardown of test_options_flow _________________________________________________
event_loop = <_UnixSelectorEventLoop running=False closed=True debug=True>, expected_lingering_tasks = False
expected_lingering_timers = False
@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."""
threads_before = frozenset(threading.enumerate())
tasks_before = asyncio.all_tasks(event_loop)
yield
event_loop.run_until_complete(event_loop.shutdown_default_executor())
if len(INSTANCES) >= 2:
count = len(INSTANCES)
for inst in INSTANCES:
inst.stop()
pytest.exit(f"Detected non stopped instances ({count}), aborting test run")
# Warn and clean-up lingering tasks and timers
# before moving on to the next test.
tasks = asyncio.all_tasks(event_loop) - tasks_before
for task in tasks:
if expected_lingering_tasks:
_LOGGER.warning("Lingering task after test %r", task)
else:
pytest.fail(f"Lingering task after test {task!r}")
task.cancel()
if tasks:
event_loop.run_until_complete(asyncio.wait(tasks))
for handle in get_scheduled_timer_handles(event_loop):
if not handle.cancelled():
with long_repr_strings():
if expected_lingering_timers:
_LOGGER.warning("Lingering timer after test %r", handle)
elif handle._args and isinstance(job := handle._args[-1], HassJob):
if job.cancel_on_shutdown:
continue
pytest.fail(f"Lingering timer after job {job!r}")
else:
> pytest.fail(f"Lingering timer after test {handle!r}")
E Failed: Lingering timer after test <TimerHandle when=124326.454898802 MQTT._async_start_misc_periodic.<locals>._async_misc() at /nix/store/gby5nizq77v05zrr656bq8ka2bv08j7z-homeassistant-2025.3.1/lib/python3.13/site-packages/homeassistant/components/mqtt/client.py:530 created at /nix/store/gby5nizq77v05zrr656bq8ka2bv08j7z-homeassistant-2025.3.1/lib/python3.13/site-packages/homeassistant/components/mqtt/client.py:536>
/nix/store/c3hj3yba8rbnrdiscl24r2qwymbsgz8p-python3.13-pytest-homeassistant-custom-component-0.13.222/lib/python3.13/site-packages/pytest_homeassistant_custom_component/plugins.py:407: Failed
--------------------------------------------------------- Captured stderr setup ---------------------------------------------------------
INFO:homeassistant.loader:Loaded sleep_as_android from custom_components.sleep_as_android
WARNING:homeassistant.loader:We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO:homeassistant.loader:Loaded mqtt from homeassistant.components.mqtt
INFO:homeassistant.loader:Loaded file_upload from homeassistant.components.file_upload
INFO:homeassistant.loader:Loaded http from homeassistant.components.http
INFO:homeassistant.setup:Setting up http
WARNING:aiohttp_fast_zlib:zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO:homeassistant.setup:Setting up file_upload
INFO:homeassistant.setup:Setting up mqtt
---------------------------------------------------------- Captured log setup -----------------------------------------------------------
INFO homeassistant.loader:loader.py:773 Loaded sleep_as_android from custom_components.sleep_as_android
WARNING homeassistant.loader:loader.py:687 We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO homeassistant.loader:loader.py:773 Loaded mqtt from homeassistant.components.mqtt
INFO homeassistant.loader:loader.py:773 Loaded file_upload from homeassistant.components.file_upload
INFO homeassistant.loader:loader.py:773 Loaded http from homeassistant.components.http
INFO homeassistant.setup:setup.py:390 Setting up http
WARNING aiohttp_fast_zlib:__init__.py:49 zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO homeassistant.setup:setup.py:390 Setting up file_upload
INFO homeassistant.setup:setup.py:390 Setting up mqtt
=============================================================== FAILURES ================================================================
______________________________________________________ test_successful_config_flow ______________________________________________________
hass = <HomeAssistant RUNNING>, mqtt_mock = <MagicMock id='140736952814960'>
async def test_successful_config_flow(hass, mqtt_mock):
"""Test a successful config flow."""
# Initialize a config flow
result = await _flow_init(hass)
# Check that the config flow shows the user form as the first step
> assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
E AttributeError: module 'homeassistant.data_entry_flow' has no attribute 'RESULT_TYPE_FORM'
tests/functional/test_config_flow.py:56: AttributeError
--------------------------------------------------------- Captured stderr setup ---------------------------------------------------------
INFO:homeassistant.loader:Loaded sleep_as_android from custom_components.sleep_as_android
WARNING:homeassistant.loader:We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO:homeassistant.loader:Loaded mqtt from homeassistant.components.mqtt
INFO:homeassistant.loader:Loaded file_upload from homeassistant.components.file_upload
INFO:homeassistant.loader:Loaded http from homeassistant.components.http
INFO:homeassistant.setup:Setting up http
WARNING:aiohttp_fast_zlib:zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO:homeassistant.setup:Setting up file_upload
INFO:homeassistant.setup:Setting up mqtt
---------------------------------------------------------- Captured log setup -----------------------------------------------------------
INFO homeassistant.loader:loader.py:773 Loaded sleep_as_android from custom_components.sleep_as_android
WARNING homeassistant.loader:loader.py:687 We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO homeassistant.loader:loader.py:773 Loaded mqtt from homeassistant.components.mqtt
INFO homeassistant.loader:loader.py:773 Loaded file_upload from homeassistant.components.file_upload
INFO homeassistant.loader:loader.py:773 Loaded http from homeassistant.components.http
INFO homeassistant.setup:setup.py:390 Setting up http
WARNING aiohttp_fast_zlib:__init__.py:49 zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO homeassistant.setup:setup.py:390 Setting up file_upload
INFO homeassistant.setup:setup.py:390 Setting up mqtt
___________________________________________________________ test_options_flow ___________________________________________________________
hass = <HomeAssistant RUNNING>, mqtt_mock = <MagicMock id='140736883282608'>
async def test_options_flow(hass, mqtt_mock):
"""Test flow for options changes."""
# setup entry
entry = MockConfigEntry(domain=DOMAIN, data=USER_INPUT, entry_id="test")
entry.add_to_hass(hass)
# Initialize an options flow for entry
result = await hass.config_entries.options.async_init(
entry.entry_id, context={"show_advanced_options": True}
)
# Verify that the first options step is a user form
> assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
E AttributeError: module 'homeassistant.data_entry_flow' has no attribute 'RESULT_TYPE_FORM'
tests/functional/test_config_flow.py:80: AttributeError
--------------------------------------------------------- Captured stderr setup ---------------------------------------------------------
INFO:homeassistant.loader:Loaded sleep_as_android from custom_components.sleep_as_android
WARNING:homeassistant.loader:We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO:homeassistant.loader:Loaded mqtt from homeassistant.components.mqtt
INFO:homeassistant.loader:Loaded file_upload from homeassistant.components.file_upload
INFO:homeassistant.loader:Loaded http from homeassistant.components.http
INFO:homeassistant.setup:Setting up http
WARNING:aiohttp_fast_zlib:zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO:homeassistant.setup:Setting up file_upload
INFO:homeassistant.setup:Setting up mqtt
---------------------------------------------------------- Captured log setup -----------------------------------------------------------
INFO homeassistant.loader:loader.py:773 Loaded sleep_as_android from custom_components.sleep_as_android
WARNING homeassistant.loader:loader.py:687 We found a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO homeassistant.loader:loader.py:773 Loaded mqtt from homeassistant.components.mqtt
INFO homeassistant.loader:loader.py:773 Loaded file_upload from homeassistant.components.file_upload
INFO homeassistant.loader:loader.py:773 Loaded http from homeassistant.components.http
INFO homeassistant.setup:setup.py:390 Setting up http
WARNING aiohttp_fast_zlib:__init__.py:49 zlib_ng and isal are not available, falling back to zlib, performance will be degraded.
INFO homeassistant.setup:setup.py:390 Setting up file_upload
INFO homeassistant.setup:setup.py:390 Setting up mqtt
________________________________________ TestAsyncSleepAsAndroidInstance.test_async_setup_entry _________________________________________
self = <tests.unit.test_instance.TestAsyncSleepAsAndroidInstance object at 0x7fffe2730550>
mocked_SleepAsAndroidInstance = <MagicMock name='SleepAsAndroidInstance' spec='SleepAsAndroidInstance' id='140736989688032'>
mocked_entity_registry = <MagicMock name='async_get' id='140736989680304'>
@patch("homeassistant.helpers.entity_registry.async_get")
@patch(__name__ + ".SleepAsAndroidInstance", spec=SleepAsAndroidInstance)
async def test_async_setup_entry(
self, mocked_SleepAsAndroidInstance, mocked_entity_registry
):
"""Set up entry."""
mocked_entry_id = PropertyMock(return_value=uuid.uuid4())
type(config_entry).entry_id = mocked_entry_id
> ret = await custom_components.sleep_as_android.async_setup_entry(
hass, config_entry
)
tests/unit/test_instance.py:218:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hass = <MagicMock id='140736988760784'>, config_entry = <MagicMock id='140736988761456'>
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Set up the integration based on config_flow."""
_LOGGER.info("Setting up %s ", config_entry.entry_id)
if DOMAIN not in hass.data:
hass.data[DOMAIN] = {}
registry = er.async_get(hass)
hass.data[DOMAIN][config_entry.entry_id] = SleepAsAndroidInstance(
hass, config_entry, registry
)
> await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.SENSOR]
)
E TypeError: object MagicMock can't be used in 'await' expression
custom_components/sleep_as_android/__init__.py:43: TypeError
--------------------------------------------------------- Captured stderr call ----------------------------------------------------------
INFO:custom_components.sleep_as_android:Setting up d51bd28a-10d6-4f85-a0ea-de07d61c164a
----------------------------------------------------------- Captured log call -----------------------------------------------------------
INFO custom_components.sleep_as_android:__init__.py:33 Setting up d51bd28a-10d6-4f85-a0ea-de07d61c164a
=========================================================== warnings summary ============================================================
tests/unit/test_instance.py:20
/tmp/hi/HA-SleepAsAndroid/tests/unit/test_instance.py:20: PytestCollectionWarning: cannot collect test class 'TestingSleepAsAndroidInstance' because it has a __init__ constructor (from: tests/unit/test_instance.py)
@pytest.mark.skip
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================== short test summary info ========================================================
FAILED tests/functional/test_config_flow.py::test_successful_config_flow - AttributeError: module 'homeassistant.data_entry_flow' has no attribute 'RESULT_TYPE_FORM'
FAILED tests/functional/test_config_flow.py::test_options_flow - AttributeError: module 'homeassistant.data_entry_flow' has no attribute 'RESULT_TYPE_FORM'
FAILED tests/unit/test_instance.py::TestAsyncSleepAsAndroidInstance::test_async_setup_entry - TypeError: object MagicMock can't be used in 'await' expression
ERROR tests/functional/test_config_flow.py::test_successful_config_flow - Failed: Lingering timer after test <TimerHandle when=124326.277909531 MQTT._async_start_misc_periodic.<locals>._async_misc() at /nix...
ERROR tests/functional/test_config_flow.py::test_options_flow - Failed: Lingering timer after test <TimerHandle when=124326.454898802 MQTT._async_start_misc_periodic.<locals>._async_misc() at /nix...
=========================================== 3 failed, 20 passed, 1 warning, 2 errors in 1.66s ===========================================
Metadata
Metadata
Assignees
Labels
No labels