Repository: home-assistant/core
File: tests/components/waterfurnace/conftest.py (Python)

Code before:

from tests.common import MockConfigEntry, load_json_object_fixture


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
    """Mock setting up a config entry."""
    with patch(
        "homeassistant.components.waterfurnace.async_setup_entry", return_value=True
    ) as mock_setup:
        yield mock_setup


@pytest.fixture
def mock_waterfurnace_client() -> Generator[Mock]:
    """Mock WaterFurnace client."""
    mock_client = Mock()
    mock_client.gwid = "TEST_GWID_12345"

    gateway_data = {
        "gwid": "TEST_GWID_12345",
        "description": "Test WaterFurnace Device",
        "awlabctypedesc": "Test ABC Type",
    }
    mock_client.devices = [WFGateway(gateway_data)]

    device_data = WFReading(load_json_object_fixture("device_data.json", DOMAIN))
    mock_client.read.return_value = device_data
    mock_client.read_with_retry.return_value = device_data

    with (
        patch(
            "homeassistant.components.waterfurnace.config_flow.WaterFurnace",
            return_value=mock_client,
        ),
        patch(
            "homeassistant.components.waterfurnace.WaterFurnace",
            return_value=mock_client,
        ),
    ):
        yield mock_client


@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
    """Return a mock config entry."""
    return MockConfigEntry(
        domain=DOMAIN,
        title="WaterFurnace test_user",
        data={
            CONF_USERNAME: "test_user",

Review comment (suggestion):
I do like the combination of the mocks, but I would recommend to put this at the top and keep the `autospec=True`. This also does more checks like making sure you call the mock correctly.

```py
@pytest.fixture
def mock_mealie_client() -> Generator[AsyncMock]:
    """Mock a Mealie client."""
    with (
        patch(
            "homeassistant.components.mealie.MealieClient",
            autospec=True,
        ) as mock_client,
        patch(
            "homeassistant.components.mealie.config_flow.MealieClient",
            new=mock_client,
        ),
    ):
        client = mock_client.return_value
        client.get_mealplans.return_value = MealplanResponse.from_json(
            load_fixture("get_mealplans.json", DOMAIN)
        )
```

Code after:

from tests.common import MockConfigEntry, load_json_object_fixture


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
    """Mock setting up a config entry."""
    with patch(
        "homeassistant.components.waterfurnace.async_setup_entry", return_value=True
    ) as mock_setup:
        yield mock_setup


@pytest.fixture
def mock_waterfurnace_client() -> Generator[Mock]:
    """Mock WaterFurnace client."""
    with (
        patch(
            "homeassistant.components.waterfurnace.config_flow.WaterFurnace",
            autospec=True,
        ) as mock_client,
        patch(
            "homeassistant.components.waterfurnace.WaterFurnace",
            new=mock_client,
        ),
    ):
        client = mock_client.return_value
        client.gwid = "TEST_GWID_12345"

        gateway_data = {
            "gwid": "TEST_GWID_12345",
            "description": "Test WaterFurnace Device",
            "awlabctypedesc": "Test ABC Type",
        }
        client.devices = [WFGateway(gateway_data)]

        device_data = WFReading(load_json_object_fixture("device_data.json", DOMAIN))
        client.read.return_value = device_data
        client.read_with_retry.return_value = device_data

        yield client


@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
    """Return a mock config entry."""
    return MockConfigEntry(
        domain=DOMAIN,
        title="WaterFurnace test_user",
        data={
            CONF_USERNAME: "test_user",