MatthewFlamm / pytest-homeassistant-custom-component

Package to automatically extract testing plugins from Home Assistant for custom component testing
MIT License
67 stars 10 forks source link

Getting Lingering timer after test error after "Remove asyncio-legacy" pull request #153

Closed vasqued2 closed 1 year ago

vasqued2 commented 1 year ago

My nightly build has started failing and it appears related to the Remove asyncio-legacy pull request. My last successful run was on 5/30.

Any suggestions appreciated.

Thanks!

Here is an extract of some of the error log...

        for handle in event_loop._scheduled:  # type: ignore[attr-defined]
            if not handle.cancelled():
                if expected_lingering_timers:
                    _LOGGER.warning("Lingering timer after test %r", handle)
                else:
>                   pytest.fail(f"Lingering timer after test {repr(handle)}")
E                   Failed: Lingering timer after test <TimerHandle when=281.488605333 Debouncer._on_debounce()>

/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/pytest_homeassistant_custom_component/plugins.py:349: Failed

Link to the full log https://github.com/vasqued2/ha-teamtracker/actions/runs/4591896864/jobs/8108458747

MatthewFlamm commented 1 year ago

This was a change from homeassistant core. A lot of built in tests had to be updated due to this change. I suggest you look there for fixes.

vasqued2 commented 1 year ago

Great. Thanks!

marcolivierarsenault commented 1 year ago

@vasqued2 I have the same issue, if you find a solution please share back.

vasqued2 commented 1 year ago

@marcolivierarsenault

For now I hacked expected_lingering_timers to ignore it. Lmk if you find a true fix.

@pytest.fixture(autouse=True)
def expected_lingering_timers() -> bool:
    """Temporary ability to bypass test failures.
    Parametrize to True to bypass the pytest failure.
    @pytest.mark.parametrize("expected_lingering_timers", [True])
    This should be removed when all lingering timers have been cleaned up.
    """
    return True

@pytest.mark.usefixtures("expected_lingering_timers")
async def test_sensor(hass, mocker):
    """ Make sure sensor gets added """

    entry = MockConfigEntry(
        domain=DOMAIN,
        title="NFL",
        data=CONFIG_DATA,
    )

    mocker.patch("locale.getlocale", return_value=("en", 0))

    #    contents = "{}"
    #    mocker.patch('aiofiles.open', return_value=mocker.mock_open(read_data=contents).return_value)

    entry.add_to_hass(hass)
    assert await hass.config_entries.async_setup(entry.entry_id)
    await hass.async_block_till_done()

    assert "teamtracker" in hass.config.components
Shulyaka commented 1 year ago

@vasqued2 Try to add the following at the end of your test_sensor function:

    assert await entry.async_unload(hass)
    await hass.async_block_till_done()
vasqued2 commented 1 year ago

@Shulyaka Thanks! That resolved it.