From 009663602ad93892ce56e93ecc1d0071930fd34c Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 5 Jan 2021 21:12:14 +0100 Subject: [PATCH] Avoid Ps4 doing I/O during tests (#44845) --- tests/components/ps4/conftest.py | 9 ++++++++- tests/components/ps4/test_media_player.py | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/components/ps4/conftest.py b/tests/components/ps4/conftest.py index 821c58d596..155f1c6d5d 100644 --- a/tests/components/ps4/conftest.py +++ b/tests/components/ps4/conftest.py @@ -18,6 +18,13 @@ def patch_save_json(): yield mock_save +@pytest.fixture +def patch_get_status(): + """Prevent save JSON being used.""" + with patch("pyps4_2ndscreen.ps4.get_status", return_value=None) as mock_get_status: + yield mock_get_status + + @pytest.fixture(autouse=True) -def patch_io(patch_load_json, patch_save_json): +def patch_io(patch_load_json, patch_save_json, patch_get_status): """Prevent PS4 doing I/O.""" diff --git a/tests/components/ps4/test_media_player.py b/tests/components/ps4/test_media_player.py index 48fb27ab6b..e65813bcbb 100644 --- a/tests/components/ps4/test_media_player.py +++ b/tests/components/ps4/test_media_player.py @@ -288,11 +288,11 @@ async def test_media_attributes_are_loaded(hass, patch_load_json): assert mock_attrs.get(ATTR_MEDIA_CONTENT_TYPE) == MOCK_TITLE_TYPE -async def test_device_info_is_set_from_status_correctly(hass): +async def test_device_info_is_set_from_status_correctly(hass, patch_get_status): """Test that device info is set correctly from status update.""" mock_d_registry = mock_device_registry(hass) - with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_STANDBY): - mock_entity_id = await setup_mock_component(hass) + patch_get_status.return_value = MOCK_STATUS_STANDBY + mock_entity_id = await setup_mock_component(hass) await hass.async_block_till_done() @@ -305,7 +305,7 @@ async def test_device_info_is_set_from_status_correctly(hass): mock_d_entries = mock_d_registry.devices mock_entry = mock_d_registry.async_get_device( - identifiers={(DOMAIN, MOCK_HOST_ID)}, connections={()} + identifiers={(DOMAIN, MOCK_HOST_ID)}, connections=set() ) assert mock_state == STATE_STANDBY