|
1 | 1 | # pylint: disable=protected-access,redefined-outer-name
|
2 | 2 | """Global fixtures for integration."""
|
| 3 | + |
3 | 4 | # Fixtures allow you to replace functions with a Mock object. You can perform
|
4 | 5 | # many options via the Mock to reflect a particular behavior from the original
|
5 | 6 | # function that you want to see without going through the function's actual logic.
|
|
27 | 28 | # This fixture enables loading custom integrations in all tests.
|
28 | 29 | # Remove to enable selective use of this fixture
|
29 | 30 | @pytest.fixture(autouse=True)
|
30 |
| -def auto_enable_custom_integrations(enable_custom_integrations): |
| 31 | +def _auto_enable_custom_integrations(enable_custom_integrations) -> None: |
31 | 32 | """Automatically enable loading custom integrations in all tests."""
|
32 |
| - yield |
| 33 | + return |
33 | 34 |
|
34 | 35 |
|
35 |
| -# This fixture is used to prevent HomeAssistant from attempting to create and dismiss persistent |
36 |
| -# notifications. These calls would fail without this fixture since the persistent_notification |
37 |
| -# integration is never loaded during a test. |
| 36 | +# This fixture is used to prevent HomeAssistant from attempting to create and dismiss |
| 37 | +# persistent notifications. These calls would fail without this fixture since the |
| 38 | +# persistent_notification integration is never loaded during a test. |
38 | 39 | @pytest.fixture(name="skip_notifications", autouse=True)
|
39 |
| -def skip_notifications_fixture(): |
| 40 | +def _skip_notifications_fixture() -> None: |
40 | 41 | """Skip notification calls."""
|
41 |
| - with patch("homeassistant.components.persistent_notification.async_create"), patch( |
42 |
| - "homeassistant.components.persistent_notification.async_dismiss" |
| 42 | + with ( |
| 43 | + patch("homeassistant.components.persistent_notification.async_create"), |
| 44 | + patch("homeassistant.components.persistent_notification.async_dismiss"), |
43 | 45 | ):
|
44 | 46 | yield
|
45 | 47 |
|
46 | 48 |
|
47 |
| -# This fixture, when used, will result in calls to async_get_data to return None. To have the call |
48 |
| -# return a value, we would add the `return_value=<VALUE_TO_RETURN>` parameter to the patch call. |
| 49 | +# This fixture, when used, will result in calls to async_get_data to return None. To |
| 50 | +# have the call return a value, we would add the `return_value=<VALUE_TO_RETURN>` |
| 51 | +# parameter to the patch call. |
49 | 52 | @pytest.fixture(name="bypass_get_data")
|
50 |
| -def bypass_get_data_fixture(): |
| 53 | +def _bypass_get_data_fixture() -> None: |
51 | 54 | """Skip calls to get data from API."""
|
52 | 55 | with patch.object(
|
53 | 56 | IntegrationBlueprintApiClient, "async_get_data", side_effect=Mock()
|
54 | 57 | ):
|
55 | 58 | yield
|
56 | 59 |
|
57 | 60 |
|
58 |
| -# In this fixture, we are forcing calls to async_get_data to raise an Exception. This is useful |
59 |
| -# for exception handling. |
| 61 | +# In this fixture, we are forcing calls to async_get_data to raise an Exception. This |
| 62 | +# is useful for exception handling. |
60 | 63 | @pytest.fixture(name="error_on_get_data")
|
61 |
| -def error_get_data_fixture(): |
| 64 | +def _error_get_data_fixture() -> None: |
62 | 65 | """Simulate error when retrieving data from API."""
|
63 | 66 | with patch.object(
|
64 | 67 | IntegrationBlueprintApiClient, "async_get_data", side_effect=Exception
|
|
0 commit comments