From 79f4b6eb6bf13d9c7dee6c97203d33857ec98d14 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 26 Aug 2020 10:53:11 -0500 Subject: [PATCH] Cleanup the rest reload test to use the pytest requests_mock fixture (#39282) --- tests/components/rest/test_sensor.py | 41 +++++++++++++--------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tests/components/rest/test_sensor.py b/tests/components/rest/test_sensor.py index 39197680887..ef4ba7a2b55 100644 --- a/tests/components/rest/test_sensor.py +++ b/tests/components/rest/test_sensor.py @@ -681,26 +681,26 @@ class TestRestData(unittest.TestCase): assert self.rest.data is None -async def test_reload(hass): +async def test_reload(hass, requests_mock): """Verify we can reload reset sensors.""" - with requests_mock.Mocker() as mock_req: - mock_req.get("http://localhost", text="test data") - await async_setup_component( - hass, - "sensor", - { - "sensor": { - "platform": "rest", - "method": "GET", - "name": "mockrest", - "resource": "http://localhost", - } - }, - ) - await hass.async_block_till_done() - await hass.async_start() - await hass.async_block_till_done() + requests_mock.get("http://localhost", text="test data") + + await async_setup_component( + hass, + "sensor", + { + "sensor": { + "platform": "rest", + "method": "GET", + "name": "mockrest", + "resource": "http://localhost", + } + }, + ) + await hass.async_block_till_done() + await hass.async_start() + await hass.async_block_till_done() assert len(hass.states.async_all()) == 1 @@ -709,10 +709,7 @@ async def test_reload(hass): yaml_path = path.join( _get_fixtures_base_path(), "fixtures", "rest/configuration.yaml", ) - with patch.object( - hass_config, "YAML_CONFIG_FILE", yaml_path - ), requests_mock.Mocker() as mock_req: - mock_req.get("http://localhost", text="test data 2") + with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path): await hass.services.async_call( "rest", SERVICE_RELOAD, {}, blocking=True, )