-
I was testing against HA core 2022.12.4 and pytest-homeassistant-custom-component 0.12.33 and my custom integration broke this week with the latest HA core update. I am in the process of fixing and have got past Poetry dependency problems but pytest-homeassistant-custom-component is failing in odd ways: hass = <async_generator object _hass at 0x11b9f35b0>, bypass_get_data = None
@pytest.mark.asyncio
async def test_successful_config_flow(hass, bypass_get_data):
"""Test a successful config flow."""
# Initialize a config flow
> result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
E AttributeError: 'async_generator' object has no attribute 'config_entries'
tests/test_config_flow.py:35: AttributeError This feels like I am doing something bad so before I raise an issue with better detail, I thought I would ask here. Possibly related, this existing fixture in @pytest.fixture(autouse=True)
def auto_enable_custom_integrations(enable_custom_integrations):
yield also generates similar errors about the hass = <async_generator object _hass at 0x11f527cd0>
@pytest.fixture
def enable_custom_integrations(hass: HomeAssistant) -> None:
"""Enable custom integrations defined in the test dir."""
> hass.data.pop(loader.DATA_CUSTOM_COMPONENTS)
E AttributeError: 'async_generator' object has no attribute 'data' |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
This is the second report of this problem. See #158. There it was found that it is testing dependent, i.e. passes in some environments but not others. Do you observe this as well? I'm not sure if this is a problem in the code that is now being uncovered, or maybe it is an order of fixture execution that might have changed. The tests in this package are not affected by this problem, which might be a starting point for investigating differences. |
Beta Was this translation helpful? Give feedback.
Thanks both - adding
asyncio_mode = "auto"
to mypyproject.toml
was what I needed. It also lets me remove the various@pytest.mark.asyncio
lines. Reading through some Stackoverflow threads, fixtures with pytest and asyncio does need to be handled with care, but thatasyncio_mode
is the cleanest answer.