alandtse/tesla

Fix async test_distance_to_arrival failing in ci

Closed

#537 opened on Mar 14, 2023

 (1 comment) (0 reactions) (0 assignees)Python (128 forks)github user discovery
good first issuehelp wantedtodo

Repository metrics

Stars
 (777 stars)
PR merge metrics
 (Avg merge 13d 8h) (14 merged PRs in 30d)

Description

This fixes an async test error. This doesn't happen when test is run individually

https://api.github.com/alandtse/tesla/blob/e017a6d049a03d2df5afafa735ac10dd9b0c83f8/tests/test_sensor.py#L633


    await setup_platform(hass, SENSOR_DOMAIN)

    state = hass.states.get("sensor.my_model_s_distance_to_arrival")
    assert state
    assert state.state
    if state.state == "unknown":
        # TODO: Fix async test_distance_to_arrival failing in ci
        # This fixes an async test error. This doesn't happen when test is run individually
        return
    if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == LENGTH_KILOMETERS:
        assert float(state.state) == round(
            DistanceConverter.convert(
                car_mock_data.VEHICLE_DATA["drive_state"][
                    "active_route_miles_to_arrival"
                ],
                LENGTH_MILES,
                LENGTH_KILOMETERS,
            ),
            2,
        )
    else:
        assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == LENGTH_MILES
        assert float(state.state) == round(
            car_mock_data.VEHICLE_DATA["drive_state"]["active_route_miles_to_arrival"],
            2,
        )

    assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DISTANCE

Contributor guide