diff --git a/tests/components/alert/test_init.py b/tests/components/alert/test_init.py index 96c36a87edc..ea029dc8a24 100644 --- a/tests/components/alert/test_init.py +++ b/tests/components/alert/test_init.py @@ -125,10 +125,7 @@ class TestAlert(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() self._setup_notify() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def _setup_notify(self): events = [] diff --git a/tests/components/apns/test_notify.py b/tests/components/apns/test_notify.py index 5c69e19435e..6c27299de5c 100644 --- a/tests/components/apns/test_notify.py +++ b/tests/components/apns/test_notify.py @@ -30,8 +30,9 @@ class TestApns(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/aurora/test_binary_sensor.py b/tests/components/aurora/test_binary_sensor.py index f90c1e2bcca..ea385d5697f 100644 --- a/tests/components/aurora/test_binary_sensor.py +++ b/tests/components/aurora/test_binary_sensor.py @@ -20,8 +20,9 @@ class TestAuroraSensorSetUp(unittest.TestCase): self.hass.config.latitude = self.lat self.hass.config.longitude = self.lon self.entities = [] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/blackbird/test_media_player.py b/tests/components/blackbird/test_media_player.py index b090368a4ce..316ed681fa0 100644 --- a/tests/components/blackbird/test_media_player.py +++ b/tests/components/blackbird/test_media_player.py @@ -203,8 +203,9 @@ class TestBlackbirdMediaPlayer(unittest.TestCase): self.media_player = self.hass.data[DATA_BLACKBIRD]["/dev/ttyUSB0-3"] self.media_player.hass = self.hass self.media_player.entity_id = "media_player.zone_3" + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Tear down the test case.""" self.hass.stop() diff --git a/tests/components/bom/test_sensor.py b/tests/components/bom/test_sensor.py index 8c647bbf6cf..49cdb3e6ee3 100644 --- a/tests/components/bom/test_sensor.py +++ b/tests/components/bom/test_sensor.py @@ -60,10 +60,7 @@ class TestBOMWeatherSensor(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() self.config = VALID_CONFIG - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @patch("requests.get", side_effect=mocked_requests) def test_setup(self, mock_get): diff --git a/tests/components/canary/test_init.py b/tests/components/canary/test_init.py index a3f6fbd7e2d..0cfbfd56de6 100644 --- a/tests/components/canary/test_init.py +++ b/tests/components/canary/test_init.py @@ -43,8 +43,9 @@ class TestCanary(unittest.TestCase): def setUp(self): """Initialize values for this test case class.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/canary/test_sensor.py b/tests/components/canary/test_sensor.py index 5a4a82ccc5a..d7d16fa5f88 100644 --- a/tests/components/canary/test_sensor.py +++ b/tests/components/canary/test_sensor.py @@ -34,10 +34,7 @@ class TestCanarySensorSetup(unittest.TestCase): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() self.config = copy.deepcopy(VALID_CONFIG) - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup_sensors(self): """Test the sensor setup.""" diff --git a/tests/components/coinmarketcap/test_sensor.py b/tests/components/coinmarketcap/test_sensor.py index f53a92a3d86..4d1fb31da95 100644 --- a/tests/components/coinmarketcap/test_sensor.py +++ b/tests/components/coinmarketcap/test_sensor.py @@ -23,10 +23,7 @@ class TestCoinMarketCapSensor(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() self.config = VALID_CONFIG - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @patch( "coinmarketcap.Market.ticker", diff --git a/tests/components/command_line/test_binary_sensor.py b/tests/components/command_line/test_binary_sensor.py index 33c28b7d65a..90871faaf78 100644 --- a/tests/components/command_line/test_binary_sensor.py +++ b/tests/components/command_line/test_binary_sensor.py @@ -14,10 +14,7 @@ class TestCommandSensorBinarySensor(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup(self): """Test sensor setup.""" diff --git a/tests/components/command_line/test_notify.py b/tests/components/command_line/test_notify.py index f20011d4482..ecdb5af91da 100644 --- a/tests/components/command_line/test_notify.py +++ b/tests/components/command_line/test_notify.py @@ -16,8 +16,9 @@ class TestCommandLine(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/command_line/test_sensor.py b/tests/components/command_line/test_sensor.py index bbf69dc73a0..ff3110f8e20 100644 --- a/tests/components/command_line/test_sensor.py +++ b/tests/components/command_line/test_sensor.py @@ -14,10 +14,7 @@ class TestCommandSensorSensor(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def update_side_effect(self, data): """Side effect function for mocking CommandSensorData.update().""" diff --git a/tests/components/command_line/test_switch.py b/tests/components/command_line/test_switch.py index ab5d0044f73..5c4a1aa336f 100644 --- a/tests/components/command_line/test_switch.py +++ b/tests/components/command_line/test_switch.py @@ -20,10 +20,7 @@ class TestCommandSwitch(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_state_none(self): """Test with none state.""" diff --git a/tests/components/configurator/test_init.py b/tests/components/configurator/test_init.py index b572609c5a2..9d696ab5f86 100644 --- a/tests/components/configurator/test_init.py +++ b/tests/components/configurator/test_init.py @@ -15,11 +15,7 @@ class TestConfigurator(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - # pylint: disable=invalid-name - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_request_least_info(self): """Test request config with least amount of data.""" diff --git a/tests/components/darksky/test_sensor.py b/tests/components/darksky/test_sensor.py index 9a48e4f1cce..be1e9849452 100644 --- a/tests/components/darksky/test_sensor.py +++ b/tests/components/darksky/test_sensor.py @@ -105,8 +105,9 @@ class TestDarkSkySetup(unittest.TestCase): self.lat = self.hass.config.latitude = 37.8267 self.lon = self.hass.config.longitude = -122.423 self.entities = [] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/darksky/test_weather.py b/tests/components/darksky/test_weather.py index 9f43534d7cd..1a2a2e156d9 100644 --- a/tests/components/darksky/test_weather.py +++ b/tests/components/darksky/test_weather.py @@ -23,8 +23,9 @@ class TestDarkSky(unittest.TestCase): self.hass.config.units = METRIC_SYSTEM self.lat = self.hass.config.latitude = 37.8267 self.lon = self.hass.config.longitude = -122.423 + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/datadog/test_init.py b/tests/components/datadog/test_init.py index 71b2af33fd3..9ba64bb43ff 100644 --- a/tests/components/datadog/test_init.py +++ b/tests/components/datadog/test_init.py @@ -21,8 +21,9 @@ class TestDatadog(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/demo/test_geo_location.py b/tests/components/demo/test_geo_location.py index 0ba3a35b891..dd4c2022c5e 100644 --- a/tests/components/demo/test_geo_location.py +++ b/tests/components/demo/test_geo_location.py @@ -26,10 +26,7 @@ class TestDemoPlatform(unittest.TestCase): def setUp(self): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup_platform(self): """Test setup of demo platform via configuration.""" diff --git a/tests/components/demo/test_notify.py b/tests/components/demo/test_notify.py index 7c7b7fa0aa1..07b6d968c84 100644 --- a/tests/components/demo/test_notify.py +++ b/tests/components/demo/test_notify.py @@ -32,8 +32,9 @@ class TestNotifyDemo(unittest.TestCase): self.events.append(event) self.hass.bus.listen(demo.EVENT_NOTIFY, record_event) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/demo/test_remote.py b/tests/components/demo/test_remote.py index 7ea31fbeb69..fa87213768d 100644 --- a/tests/components/demo/test_remote.py +++ b/tests/components/demo/test_remote.py @@ -24,8 +24,9 @@ class TestDemoRemote(unittest.TestCase): ) self.hass.block_till_done() - # pylint: disable=invalid-name - def tearDown(self): + self.addCleanup(self.tear_down_cleanup) + + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/dte_energy_bridge/test_sensor.py b/tests/components/dte_energy_bridge/test_sensor.py index 34f0a0a28c3..38d712468c0 100644 --- a/tests/components/dte_energy_bridge/test_sensor.py +++ b/tests/components/dte_energy_bridge/test_sensor.py @@ -17,10 +17,7 @@ class TestDteEnergyBridgeSetup(unittest.TestCase): def setUp(self): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup_with_config(self): """Test the platform setup with configuration.""" diff --git a/tests/components/dyson/test_climate.py b/tests/components/dyson/test_climate.py index af17d1f0ab4..2d769231f1b 100644 --- a/tests/components/dyson/test_climate.py +++ b/tests/components/dyson/test_climate.py @@ -111,8 +111,9 @@ class DysonTest(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/dyson/test_fan.py b/tests/components/dyson/test_fan.py index d4db6051960..807cf3565ed 100644 --- a/tests/components/dyson/test_fan.py +++ b/tests/components/dyson/test_fan.py @@ -136,8 +136,9 @@ class DysonSetupTest(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() @@ -173,8 +174,9 @@ class DysonTest(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/dyson/test_init.py b/tests/components/dyson/test_init.py index 37cc69b6765..d2c36beb7d5 100644 --- a/tests/components/dyson/test_init.py +++ b/tests/components/dyson/test_init.py @@ -41,8 +41,9 @@ class DysonTest(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/dyson/test_sensor.py b/tests/components/dyson/test_sensor.py index 92bd3bba9aa..d15826863bb 100644 --- a/tests/components/dyson/test_sensor.py +++ b/tests/components/dyson/test_sensor.py @@ -84,8 +84,9 @@ class DysonTest(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/dyson/test_vacuum.py b/tests/components/dyson/test_vacuum.py index fc801cbe649..0ff19665807 100644 --- a/tests/components/dyson/test_vacuum.py +++ b/tests/components/dyson/test_vacuum.py @@ -70,8 +70,9 @@ class DysonTest(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/efergy/test_sensor.py b/tests/components/efergy/test_sensor.py index 252669233e5..7d1d928cef8 100644 --- a/tests/components/efergy/test_sensor.py +++ b/tests/components/efergy/test_sensor.py @@ -75,8 +75,9 @@ class TestEfergySensor(unittest.TestCase): """Initialize values for this test case class.""" self.hass = get_test_home_assistant() self.config = ONE_SENSOR_CONFIG + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/fail2ban/test_sensor.py b/tests/components/fail2ban/test_sensor.py index b164cc93f2e..fa78c9b1bbf 100644 --- a/tests/components/fail2ban/test_sensor.py +++ b/tests/components/fail2ban/test_sensor.py @@ -66,10 +66,7 @@ class TestBanSensor(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @patch("os.path.isfile", Mock(return_value=True)) def test_setup(self): diff --git a/tests/components/fan/test_init.py b/tests/components/fan/test_init.py index f27a3ff8ab6..134a5976baa 100644 --- a/tests/components/fan/test_init.py +++ b/tests/components/fan/test_init.py @@ -21,8 +21,9 @@ class TestFanEntity(unittest.TestCase): def setUp(self): """Set up test data.""" self.fan = BaseFan() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Tear down unit test data.""" self.fan = None diff --git a/tests/components/feedreader/test_init.py b/tests/components/feedreader/test_init.py index 823bdf6eb63..1983cb5ab8d 100644 --- a/tests/components/feedreader/test_init.py +++ b/tests/components/feedreader/test_init.py @@ -42,10 +42,7 @@ class TestFeedreaderComponent(unittest.TestCase): data_file = self.hass.config.path(f"{feedreader.DOMAIN}.pickle") if exists(data_file): remove(data_file) - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup_one_feed(self): """Test the general setup of this component.""" diff --git a/tests/components/file/test_notify.py b/tests/components/file/test_notify.py index e4ae125949a..d7f380cf6da 100644 --- a/tests/components/file/test_notify.py +++ b/tests/components/file/test_notify.py @@ -17,8 +17,9 @@ class TestNotifyFile(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/geo_rss_events/test_sensor.py b/tests/components/geo_rss_events/test_sensor.py index 9f7cdd3faab..61e4ab1e7d1 100644 --- a/tests/components/geo_rss_events/test_sensor.py +++ b/tests/components/geo_rss_events/test_sensor.py @@ -42,10 +42,7 @@ class TestGeoRssServiceUpdater(unittest.TestCase): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() # self.config = VALID_CONFIG_WITHOUT_CATEGORIES - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @staticmethod def _generate_mock_feed_entry( diff --git a/tests/components/google_wifi/test_sensor.py b/tests/components/google_wifi/test_sensor.py index 69db8de184b..ff3ec0429fa 100644 --- a/tests/components/google_wifi/test_sensor.py +++ b/tests/components/google_wifi/test_sensor.py @@ -40,10 +40,7 @@ class TestGoogleWifiSetup(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @requests_mock.Mocker() def test_setup_minimum(self, mock_req): @@ -92,10 +89,7 @@ class TestGoogleWifiSensor(unittest.TestCase): self.hass = get_test_home_assistant() with requests_mock.Mocker() as mock_req: self.setup_api(MOCK_DATA, mock_req) - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def setup_api(self, data, mock_req): """Set up API with fake data.""" diff --git a/tests/components/group/test_init.py b/tests/components/group/test_init.py index c4d98ad37cc..ff5f3a30f75 100644 --- a/tests/components/group/test_init.py +++ b/tests/components/group/test_init.py @@ -28,11 +28,7 @@ class TestComponentsGroup(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - # pylint: disable=invalid-name - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup_group_with_mixed_groupable_states(self): """Try to set up a group with mixed groupable states.""" diff --git a/tests/components/group/test_notify.py b/tests/components/group/test_notify.py index 0925b318c9e..b120cf2cea4 100644 --- a/tests/components/group/test_notify.py +++ b/tests/components/group/test_notify.py @@ -63,8 +63,9 @@ class TestNotifyGroup(unittest.TestCase): ).result() assert self.service is not None + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/hddtemp/test_sensor.py b/tests/components/hddtemp/test_sensor.py index 84315afb476..4062d737ea2 100644 --- a/tests/components/hddtemp/test_sensor.py +++ b/tests/components/hddtemp/test_sensor.py @@ -87,10 +87,7 @@ class TestHDDTempSensor(unittest.TestCase): "model": "WDC WD15EARS-00Z5B1", }, } - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @patch("telnetlib.Telnet", new=TelnetMock) def test_hddtemp_min_config(self): diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index ba0e0b9f1c0..b47eca9f051 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -26,8 +26,9 @@ class TestComponentHistory(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/history_stats/test_sensor.py b/tests/components/history_stats/test_sensor.py index 900af4988e2..25cca7615a7 100644 --- a/tests/components/history_stats/test_sensor.py +++ b/tests/components/history_stats/test_sensor.py @@ -23,10 +23,7 @@ class TestHistoryStatsSensor(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup(self): """Test the history statistics sensor setup.""" diff --git a/tests/components/homeassistant/test_init.py b/tests/components/homeassistant/test_init.py index b9309d70d63..3419aea06af 100644 --- a/tests/components/homeassistant/test_init.py +++ b/tests/components/homeassistant/test_init.py @@ -120,11 +120,7 @@ class TestComponentsCore(unittest.TestCase): self.hass.states.set("light.Bowl", STATE_ON) self.hass.states.set("light.Ceiling", STATE_OFF) - - # pylint: disable=invalid-name - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_is_on(self): """Test is_on method.""" diff --git a/tests/components/homematic/test_notify.py b/tests/components/homematic/test_notify.py index 411be41eb39..e1bd2f4f229 100644 --- a/tests/components/homematic/test_notify.py +++ b/tests/components/homematic/test_notify.py @@ -14,8 +14,9 @@ class TestHomematicNotify(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/imap_email_content/test_sensor.py b/tests/components/imap_email_content/test_sensor.py index ee39bac51ef..3a0c006d15f 100644 --- a/tests/components/imap_email_content/test_sensor.py +++ b/tests/components/imap_email_content/test_sensor.py @@ -37,10 +37,7 @@ class EmailContentSensor(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_allowed_sender(self): """Test emails from allowed sender.""" diff --git a/tests/components/influxdb/test_init.py b/tests/components/influxdb/test_init.py index bdfd41eae83..cdbb39ba3ce 100644 --- a/tests/components/influxdb/test_init.py +++ b/tests/components/influxdb/test_init.py @@ -29,8 +29,9 @@ class TestInfluxDB(unittest.TestCase): self.hass = get_test_home_assistant() self.handler_method = None self.hass.bus.listen = mock.Mock() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Clear data.""" self.hass.stop() diff --git a/tests/components/kira/test_init.py b/tests/components/kira/test_init.py index 8656ac23264..b57d8c97617 100644 --- a/tests/components/kira/test_init.py +++ b/tests/components/kira/test_init.py @@ -45,8 +45,9 @@ class TestKiraSetup(unittest.TestCase): self._module_patcher.start() self.work_dir = tempfile.mkdtemp() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() self._module_patcher.stop() diff --git a/tests/components/kira/test_remote.py b/tests/components/kira/test_remote.py index b1ac7ea12fc..c946823474c 100644 --- a/tests/components/kira/test_remote.py +++ b/tests/components/kira/test_remote.py @@ -30,10 +30,7 @@ class TestKiraSensor(unittest.TestCase): self.mock_kira = MagicMock() self.hass.data[kira.DOMAIN] = {kira.CONF_REMOTE: {}} self.hass.data[kira.DOMAIN][kira.CONF_REMOTE]["kira"] = self.mock_kira - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_service_call(self): """Test Kira's ability to send commands.""" diff --git a/tests/components/kira/test_sensor.py b/tests/components/kira/test_sensor.py index 2fae36dc670..21572a8735b 100644 --- a/tests/components/kira/test_sensor.py +++ b/tests/components/kira/test_sensor.py @@ -28,10 +28,7 @@ class TestKiraSensor(unittest.TestCase): mock_kira = MagicMock() self.hass.data[kira.DOMAIN] = {kira.CONF_SENSOR: {}} self.hass.data[kira.DOMAIN][kira.CONF_SENSOR]["kira"] = mock_kira - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) # pylint: disable=protected-access def test_kira_sensor_callback(self): diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index 2fa22cd81dd..b46be5c926c 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -32,9 +32,9 @@ class TestLight(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - # pylint: disable=invalid-name - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/logbook/test_init.py b/tests/components/logbook/test_init.py index e96bb876b61..91b90426d3f 100644 --- a/tests/components/logbook/test_init.py +++ b/tests/components/logbook/test_init.py @@ -44,10 +44,7 @@ class TestComponentLogbook(unittest.TestCase): init_recorder_component(self.hass) # Force an in memory DB with patch("homeassistant.components.http.start_http_server_and_save_config"): assert setup_component(self.hass, logbook.DOMAIN, self.EMPTY_CONFIG) - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_service_call_create_logbook_entry(self): """Test if service call create log book entry.""" diff --git a/tests/components/logentries/test_init.py b/tests/components/logentries/test_init.py index f850a7dd62b..2d7b7ee6c25 100644 --- a/tests/components/logentries/test_init.py +++ b/tests/components/logentries/test_init.py @@ -16,8 +16,9 @@ class TestLogentries(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/london_air/test_sensor.py b/tests/components/london_air/test_sensor.py index f596750ea7d..066fc357a50 100644 --- a/tests/components/london_air/test_sensor.py +++ b/tests/components/london_air/test_sensor.py @@ -18,10 +18,7 @@ class TestLondonAirSensor(unittest.TestCase): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() self.config = VALID_CONFIG - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @requests_mock.Mocker() def test_setup(self, mock_req): diff --git a/tests/components/manual_mqtt/test_alarm_control_panel.py b/tests/components/manual_mqtt/test_alarm_control_panel.py index a23382d9f78..996811224c6 100644 --- a/tests/components/manual_mqtt/test_alarm_control_panel.py +++ b/tests/components/manual_mqtt/test_alarm_control_panel.py @@ -35,8 +35,9 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase): self.hass = get_test_home_assistant() self.hass.config_entries._async_schedule_save = Mock() self.mock_publish = mock_mqtt_component(self.hass) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/media_player/test_async_helpers.py b/tests/components/media_player/test_async_helpers.py index ac0d70bded9..12414801a52 100644 --- a/tests/components/media_player/test_async_helpers.py +++ b/tests/components/media_player/test_async_helpers.py @@ -146,8 +146,9 @@ class TestAsyncMediaPlayer(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() self.player = AsyncMediaPlayer(self.hass) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Shut down test instance.""" self.hass.stop() @@ -207,8 +208,9 @@ class TestSyncMediaPlayer(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() self.player = SyncMediaPlayer(self.hass) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Shut down test instance.""" self.hass.stop() diff --git a/tests/components/mochad/test_light.py b/tests/components/mochad/test_light.py index 2dd385f0253..eb9cf047d02 100644 --- a/tests/components/mochad/test_light.py +++ b/tests/components/mochad/test_light.py @@ -28,10 +28,7 @@ class TestMochadSwitchSetup(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @mock.patch("homeassistant.components.mochad.light.MochadLight") def test_setup_adds_proper_devices(self, mock_light): diff --git a/tests/components/mochad/test_switch.py b/tests/components/mochad/test_switch.py index 699edfe899c..66f84c16fee 100644 --- a/tests/components/mochad/test_switch.py +++ b/tests/components/mochad/test_switch.py @@ -30,10 +30,7 @@ class TestMochadSwitchSetup(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @mock.patch("homeassistant.components.mochad.switch.MochadSwitch") def test_setup_adds_proper_devices(self, mock_switch): diff --git a/tests/components/mold_indicator/test_sensor.py b/tests/components/mold_indicator/test_sensor.py index 5f3b223bf66..423c728ff72 100644 --- a/tests/components/mold_indicator/test_sensor.py +++ b/tests/components/mold_indicator/test_sensor.py @@ -32,8 +32,9 @@ class TestSensorMoldIndicator(unittest.TestCase): self.hass.states.set( "test.indoorhumidity", "50", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE} ) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 94961ebfe7a..475f337f53e 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -92,8 +92,9 @@ class TestMQTTComponent(unittest.TestCase): self.hass = get_test_home_assistant() mock_mqtt_component(self.hass) self.calls = [] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() @@ -307,8 +308,9 @@ class TestMQTTCallbacks(unittest.TestCase): self.hass = get_test_home_assistant() mock_mqtt_client(self.hass) self.calls = [] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/nsw_fuel_station/test_sensor.py b/tests/components/nsw_fuel_station/test_sensor.py index 861aa155f4f..d4e10ff5129 100644 --- a/tests/components/nsw_fuel_station/test_sensor.py +++ b/tests/components/nsw_fuel_station/test_sensor.py @@ -79,10 +79,7 @@ class TestNSWFuelStation(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() self.config = VALID_CONFIG - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @patch( "homeassistant.components.nsw_fuel_station.sensor.FuelCheckClient", diff --git a/tests/components/nx584/test_binary_sensor.py b/tests/components/nx584/test_binary_sensor.py index a02a4fbe3af..a9f3e6df7f6 100644 --- a/tests/components/nx584/test_binary_sensor.py +++ b/tests/components/nx584/test_binary_sensor.py @@ -36,8 +36,9 @@ class TestNX584SensorSetup(unittest.TestCase): client = nx584_client.Client.return_value client.list_zones.return_value = self.fake_zones client.get_version.return_value = "1.1" + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() self._mock_client.stop() diff --git a/tests/components/openhardwaremonitor/test_sensor.py b/tests/components/openhardwaremonitor/test_sensor.py index db44216c535..6c8776f740d 100644 --- a/tests/components/openhardwaremonitor/test_sensor.py +++ b/tests/components/openhardwaremonitor/test_sensor.py @@ -21,8 +21,9 @@ class TestOpenHardwareMonitorSetup(unittest.TestCase): "port": 8085, } } + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/panel_iframe/test_init.py b/tests/components/panel_iframe/test_init.py index b38f3c4b1fa..7d42c4d03d3 100644 --- a/tests/components/panel_iframe/test_init.py +++ b/tests/components/panel_iframe/test_init.py @@ -14,10 +14,7 @@ class TestPanelIframe(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_wrong_config(self): """Test setup with wrong configuration.""" diff --git a/tests/components/pilight/test_init.py b/tests/components/pilight/test_init.py index 53b1ec3a94d..5c2acc0d8f2 100644 --- a/tests/components/pilight/test_init.py +++ b/tests/components/pilight/test_init.py @@ -71,8 +71,9 @@ class TestPilight(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() self.skip_teardown_stop = False + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" if not self.skip_teardown_stop: self.hass.stop() @@ -374,10 +375,7 @@ class TestPilightCallrateThrottler(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_call_rate_delay_throttle_disabled(self): """Test that the limiter is a noop if no delay set.""" diff --git a/tests/components/proximity/test_init.py b/tests/components/proximity/test_init.py index d3b6f9274e5..55aca3223f0 100644 --- a/tests/components/proximity/test_init.py +++ b/tests/components/proximity/test_init.py @@ -25,10 +25,7 @@ class TestProximity(unittest.TestCase): "zoning", {"name": "work", "latitude": 2.3, "longitude": 1.3, "radius": 10}, ) - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_proximities(self): """Test a list of proximities.""" diff --git a/tests/components/pushbullet/test_notify.py b/tests/components/pushbullet/test_notify.py index 930d9261f9c..b0fb55e152d 100644 --- a/tests/components/pushbullet/test_notify.py +++ b/tests/components/pushbullet/test_notify.py @@ -18,8 +18,9 @@ class TestPushBullet(unittest.TestCase): def setUp(self): """Initialize values for this test case class.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that we started.""" self.hass.stop() diff --git a/tests/components/radarr/test_sensor.py b/tests/components/radarr/test_sensor.py index 0e76e99e721..96575f81154 100644 --- a/tests/components/radarr/test_sensor.py +++ b/tests/components/radarr/test_sensor.py @@ -208,8 +208,9 @@ class TestRadarrSetup(unittest.TestCase): self.DEVICES = [] self.hass = get_test_home_assistant() self.hass.config.time_zone = "America/Los_Angeles" + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/recorder/test_init.py b/tests/components/recorder/test_init.py index 1931a367ee8..a325f78d83c 100644 --- a/tests/components/recorder/test_init.py +++ b/tests/components/recorder/test_init.py @@ -28,8 +28,9 @@ class TestRecorder(unittest.TestCase): self.hass = get_test_home_assistant() init_recorder_component(self.hass) self.hass.start() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/recorder/test_models.py b/tests/components/recorder/test_models.py index 276194b5d6c..f2eb28b3d01 100644 --- a/tests/components/recorder/test_models.py +++ b/tests/components/recorder/test_models.py @@ -88,8 +88,9 @@ class TestRecorderRuns(unittest.TestCase): session.query(Events).delete() session.query(States).delete() session.query(RecorderRuns).delete() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Clean up.""" self.session.rollback() diff --git a/tests/components/recorder/test_purge.py b/tests/components/recorder/test_purge.py index 4ec08c432b0..ac59ca5e2d7 100644 --- a/tests/components/recorder/test_purge.py +++ b/tests/components/recorder/test_purge.py @@ -21,8 +21,9 @@ class TestRecorderPurge(unittest.TestCase): self.hass = get_test_home_assistant() init_recorder_component(self.hass) self.hass.start() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/reddit/test_sensor.py b/tests/components/reddit/test_sensor.py index 33c7fae76b0..faa3679f492 100644 --- a/tests/components/reddit/test_sensor.py +++ b/tests/components/reddit/test_sensor.py @@ -157,8 +157,9 @@ class TestRedditSetup(unittest.TestCase): def setUp(self): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/remember_the_milk/test_init.py b/tests/components/remember_the_milk/test_init.py index 2bba18f0052..1c9438c602b 100644 --- a/tests/components/remember_the_milk/test_init.py +++ b/tests/components/remember_the_milk/test_init.py @@ -30,8 +30,9 @@ class TestConfiguration(unittest.TestCase): } } ) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Exit Home Assistant.""" self.hass.stop() diff --git a/tests/components/remote/test_init.py b/tests/components/remote/test_init.py index 031131276fe..eb47d365f83 100644 --- a/tests/components/remote/test_init.py +++ b/tests/components/remote/test_init.py @@ -28,11 +28,7 @@ class TestRemote(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - # pylint: disable=invalid-name - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_is_on(self): """Test is_on.""" diff --git a/tests/components/rest/test_binary_sensor.py b/tests/components/rest/test_binary_sensor.py index 762c1705d77..4d893a2ef64 100644 --- a/tests/components/rest/test_binary_sensor.py +++ b/tests/components/rest/test_binary_sensor.py @@ -33,10 +33,7 @@ class TestRestBinarySensorSetup(unittest.TestCase): self.hass = get_test_home_assistant() # Reset for this test. self.DEVICES = [] - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup_missing_config(self): """Test setup with configuration missing required entries.""" @@ -162,10 +159,7 @@ class TestRestBinarySensor(unittest.TestCase): self.binary_sensor = rest.RestBinarySensor( self.hass, self.rest, self.name, self.device_class, self.value_template ) - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def update_side_effect(self, data): """Side effect function for mocking RestData.update().""" diff --git a/tests/components/rest/test_sensor.py b/tests/components/rest/test_sensor.py index 77d88f083e4..90a8b8d361e 100644 --- a/tests/components/rest/test_sensor.py +++ b/tests/components/rest/test_sensor.py @@ -25,10 +25,7 @@ class TestRestSensorSetup(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_setup_missing_config(self): """Test setup with configuration missing required entries.""" @@ -237,10 +234,7 @@ class TestRestSensor(unittest.TestCase): self.resource_template, self.json_attrs_path, ) - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def update_side_effect(self, data, headers): """Side effect function for mocking RestData.update().""" diff --git a/tests/components/rfxtrx/test_cover.py b/tests/components/rfxtrx/test_cover.py index d85ea5cf6f4..9ecbcda3409 100644 --- a/tests/components/rfxtrx/test_cover.py +++ b/tests/components/rfxtrx/test_cover.py @@ -18,8 +18,9 @@ class TestCoverRfxtrx(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() mock_component("rfxtrx") + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = [] rfxtrx_core.RFX_DEVICES = {} diff --git a/tests/components/rfxtrx/test_init.py b/tests/components/rfxtrx/test_init.py index 6b75cc92fc6..669ec24efc3 100644 --- a/tests/components/rfxtrx/test_init.py +++ b/tests/components/rfxtrx/test_init.py @@ -18,8 +18,9 @@ class TestRFXTRX(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" rfxtrx.RECEIVED_EVT_SUBSCRIBERS = [] rfxtrx.RFX_DEVICES = {} diff --git a/tests/components/rfxtrx/test_light.py b/tests/components/rfxtrx/test_light.py index a5230cc5f3c..1a8ee94d9a4 100644 --- a/tests/components/rfxtrx/test_light.py +++ b/tests/components/rfxtrx/test_light.py @@ -18,8 +18,9 @@ class TestLightRfxtrx(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() mock_component(self.hass, "rfxtrx") + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = [] rfxtrx_core.RFX_DEVICES = {} diff --git a/tests/components/rfxtrx/test_sensor.py b/tests/components/rfxtrx/test_sensor.py index e258ebb9aa1..fa713a024cf 100644 --- a/tests/components/rfxtrx/test_sensor.py +++ b/tests/components/rfxtrx/test_sensor.py @@ -18,8 +18,9 @@ class TestSensorRfxtrx(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() mock_component(self.hass, "rfxtrx") + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = [] rfxtrx_core.RFX_DEVICES = {} diff --git a/tests/components/rfxtrx/test_switch.py b/tests/components/rfxtrx/test_switch.py index 66da197aae8..cc1a6008fa8 100644 --- a/tests/components/rfxtrx/test_switch.py +++ b/tests/components/rfxtrx/test_switch.py @@ -18,8 +18,9 @@ class TestSwitchRfxtrx(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() mock_component(self.hass, "rfxtrx") + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = [] rfxtrx_core.RFX_DEVICES = {} diff --git a/tests/components/ring/test_init.py b/tests/components/ring/test_init.py index 39d2c63ffdd..4ad056150dd 100644 --- a/tests/components/ring/test_init.py +++ b/tests/components/ring/test_init.py @@ -23,8 +23,9 @@ class TestRing(unittest.TestCase): """Initialize values for this test case class.""" self.hass = get_test_home_assistant() self.config = VALID_CONFIG + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/scene/test_init.py b/tests/components/scene/test_init.py index bff88d8e660..7f8308d3e20 100644 --- a/tests/components/scene/test_init.py +++ b/tests/components/scene/test_init.py @@ -35,8 +35,9 @@ class TestScene(unittest.TestCase): assert not self.light_1.is_on assert not self.light_2.is_on + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py index 8dbe43a25ff..7e5d77a8555 100644 --- a/tests/components/script/test_init.py +++ b/tests/components/script/test_init.py @@ -73,8 +73,9 @@ class TestScriptComponent(unittest.TestCase): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - # pylint: disable=invalid-name - def tearDown(self): + self.addCleanup(self.tear_down_cleanup) + + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/season/test_sensor.py b/tests/components/season/test_sensor.py index 279291d6da5..8918099405a 100644 --- a/tests/components/season/test_sensor.py +++ b/tests/components/season/test_sensor.py @@ -45,10 +45,7 @@ class TestSeason(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_season_should_be_summer_northern_astronomical(self): """Test that season should be summer.""" diff --git a/tests/components/shell_command/test_init.py b/tests/components/shell_command/test_init.py index 8743ab27bd7..76f81ea72df 100644 --- a/tests/components/shell_command/test_init.py +++ b/tests/components/shell_command/test_init.py @@ -40,8 +40,9 @@ class TestShellCommand(unittest.TestCase): """ self.hass = get_test_home_assistant() asyncio.get_child_watcher().attach_loop(self.hass.loop) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/sigfox/test_sensor.py b/tests/components/sigfox/test_sensor.py index c4af07b5799..923392bbaf8 100644 --- a/tests/components/sigfox/test_sensor.py +++ b/tests/components/sigfox/test_sensor.py @@ -39,10 +39,7 @@ class TestSigfoxSensor(unittest.TestCase): def setUp(self): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_invalid_credentials(self): """Test for invalid credentials.""" diff --git a/tests/components/sleepiq/test_binary_sensor.py b/tests/components/sleepiq/test_binary_sensor.py index fbafe8aad7d..ab51a08d4c6 100644 --- a/tests/components/sleepiq/test_binary_sensor.py +++ b/tests/components/sleepiq/test_binary_sensor.py @@ -28,8 +28,9 @@ class TestSleepIQBinarySensorSetup(unittest.TestCase): self.password = "bar" self.config = {"username": self.username, "password": self.password} self.DEVICES = [] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/sleepiq/test_init.py b/tests/components/sleepiq/test_init.py index 9c1c0972fac..850d42763d1 100644 --- a/tests/components/sleepiq/test_init.py +++ b/tests/components/sleepiq/test_init.py @@ -37,8 +37,9 @@ class TestSleepIQ(unittest.TestCase): self.config = { "sleepiq": {"username": self.username, "password": self.password} } + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/sleepiq/test_sensor.py b/tests/components/sleepiq/test_sensor.py index d94cd7e4063..3e5cbc657e1 100644 --- a/tests/components/sleepiq/test_sensor.py +++ b/tests/components/sleepiq/test_sensor.py @@ -28,8 +28,9 @@ class TestSleepIQSensorSetup(unittest.TestCase): self.password = "bar" self.config = {"username": self.username, "password": self.password} self.DEVICES = [] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/smtp/test_notify.py b/tests/components/smtp/test_notify.py index f74d47a21c1..d99ee82d4ef 100644 --- a/tests/components/smtp/test_notify.py +++ b/tests/components/smtp/test_notify.py @@ -34,8 +34,9 @@ class TestNotifySmtp(unittest.TestCase): "Home Assistant", 0, ) + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/splunk/test_init.py b/tests/components/splunk/test_init.py index 256c78af502..2822e40440f 100644 --- a/tests/components/splunk/test_init.py +++ b/tests/components/splunk/test_init.py @@ -19,8 +19,9 @@ class TestSplunk(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/statsd/test_init.py b/tests/components/statsd/test_init.py index 4c7e9d29fee..9564de85a97 100644 --- a/tests/components/statsd/test_init.py +++ b/tests/components/statsd/test_init.py @@ -19,8 +19,9 @@ class TestStatsd(unittest.TestCase): def setUp(self): # pylint: disable=invalid-name """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/switch/test_init.py b/tests/components/switch/test_init.py index 6605d19d46f..5853e5faee2 100644 --- a/tests/components/switch/test_init.py +++ b/tests/components/switch/test_init.py @@ -22,11 +22,7 @@ class TestSwitch(unittest.TestCase): platform.init() # Switch 1 is ON, switch 2 is OFF self.switch_1, self.switch_2, self.switch_3 = platform.ENTITIES - - # pylint: disable=invalid-name - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_methods(self): """Test is_on, turn_on, turn_off methods.""" diff --git a/tests/components/time_date/test_sensor.py b/tests/components/time_date/test_sensor.py index 80a081cd524..c5e8ccecc40 100644 --- a/tests/components/time_date/test_sensor.py +++ b/tests/components/time_date/test_sensor.py @@ -23,8 +23,9 @@ class TestTimeDateSensor(unittest.TestCase): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() self.DEFAULT_TIME_ZONE = dt_util.DEFAULT_TIME_ZONE + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop everything that was started.""" dt_util.set_default_time_zone(self.DEFAULT_TIME_ZONE) self.hass.stop() diff --git a/tests/components/transport_nsw/test_sensor.py b/tests/components/transport_nsw/test_sensor.py index 0d12589372e..d2aa8fb9387 100644 --- a/tests/components/transport_nsw/test_sensor.py +++ b/tests/components/transport_nsw/test_sensor.py @@ -37,10 +37,7 @@ class TestRMVtransportSensor(unittest.TestCase): def setUp(self): """Set up things to run when tests begin.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @patch("TransportNSW.TransportNSW.get_departures", side_effect=get_departuresMock) def test_transportnsw_config(self, mock_get_departures): diff --git a/tests/components/uk_transport/test_sensor.py b/tests/components/uk_transport/test_sensor.py index 7385592fe93..81cfa7ae8ae 100644 --- a/tests/components/uk_transport/test_sensor.py +++ b/tests/components/uk_transport/test_sensor.py @@ -49,10 +49,7 @@ class TestUkTransportSensor(unittest.TestCase): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() self.config = VALID_CONFIG - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @requests_mock.Mocker() def test_bus(self, mock_req): diff --git a/tests/components/universal/test_media_player.py b/tests/components/universal/test_media_player.py index bf780d33922..b50906649f0 100644 --- a/tests/components/universal/test_media_player.py +++ b/tests/components/universal/test_media_player.py @@ -220,8 +220,9 @@ class TestMediaPlayer(unittest.TestCase): "shuffle": self.mock_shuffle_switch_id, }, } + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/uptime/test_sensor.py b/tests/components/uptime/test_sensor.py index 111114d8aca..08758741b95 100644 --- a/tests/components/uptime/test_sensor.py +++ b/tests/components/uptime/test_sensor.py @@ -16,10 +16,7 @@ class TestUptimeSensor(unittest.TestCase): def setUp(self): """Set up things to run when tests begin.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_uptime_min_config(self): """Test minimum uptime configuration.""" diff --git a/tests/components/uvc/test_camera.py b/tests/components/uvc/test_camera.py index 22df898f006..35e6c82ded6 100644 --- a/tests/components/uvc/test_camera.py +++ b/tests/components/uvc/test_camera.py @@ -21,10 +21,7 @@ class TestUVCSetup(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @mock.patch("uvcclient.nvr.UVCRemote") @mock.patch.object(uvc, "UnifiVideoCamera") diff --git a/tests/components/vultr/test_binary_sensor.py b/tests/components/vultr/test_binary_sensor.py index 609cdbf6a9e..af99dc12c5f 100644 --- a/tests/components/vultr/test_binary_sensor.py +++ b/tests/components/vultr/test_binary_sensor.py @@ -42,8 +42,9 @@ class TestVultrBinarySensorSetup(unittest.TestCase): {CONF_SUBSCRIPTION: "123456", CONF_NAME: "Failed Server"}, {CONF_SUBSCRIPTION: "555555", CONF_NAME: vultr.DEFAULT_NAME}, ] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop our started services.""" self.hass.stop() diff --git a/tests/components/vultr/test_init.py b/tests/components/vultr/test_init.py index 6035ac547af..9ce96d7969c 100644 --- a/tests/components/vultr/test_init.py +++ b/tests/components/vultr/test_init.py @@ -21,8 +21,9 @@ class TestVultr(unittest.TestCase): """Initialize values for this test case class.""" self.hass = get_test_home_assistant() self.config = VALID_CONFIG + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that we started.""" self.hass.stop() diff --git a/tests/components/vultr/test_sensor.py b/tests/components/vultr/test_sensor.py index 1ced0fec82f..8e9cb606d1e 100644 --- a/tests/components/vultr/test_sensor.py +++ b/tests/components/vultr/test_sensor.py @@ -51,10 +51,7 @@ class TestVultrSensorSetup(unittest.TestCase): CONF_MONITORED_CONDITIONS: ["pending_charges"], }, ] - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @requests_mock.Mocker() def test_sensor(self, mock): diff --git a/tests/components/vultr/test_switch.py b/tests/components/vultr/test_switch.py index 594617bdfd9..77eb1e7a8c6 100644 --- a/tests/components/vultr/test_switch.py +++ b/tests/components/vultr/test_switch.py @@ -42,8 +42,9 @@ class TestVultrSwitchSetup(unittest.TestCase): {CONF_SUBSCRIPTION: "123456", CONF_NAME: "Failed Server"}, {CONF_SUBSCRIPTION: "555555", CONF_NAME: vultr.DEFAULT_NAME}, ] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop our started services.""" self.hass.stop() diff --git a/tests/components/wake_on_lan/test_switch.py b/tests/components/wake_on_lan/test_switch.py index d99bc1ccb4f..6db8018593d 100644 --- a/tests/components/wake_on_lan/test_switch.py +++ b/tests/components/wake_on_lan/test_switch.py @@ -35,10 +35,7 @@ class TestWolSwitch(unittest.TestCase): def setUp(self): """Set up things to be run when tests are started.""" self.hass = get_test_home_assistant() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) @patch("wakeonlan.send_magic_packet", new=send_magic_packet) @patch("subprocess.call", new=call) diff --git a/tests/components/weather/test_weather.py b/tests/components/weather/test_weather.py index d026cd6ee86..10161a0d634 100644 --- a/tests/components/weather/test_weather.py +++ b/tests/components/weather/test_weather.py @@ -33,8 +33,9 @@ class TestWeather(unittest.TestCase): self.hass, weather.DOMAIN, {"weather": {"platform": "demo"}} ) self.hass.block_till_done() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): + def tear_down_cleanup(self): """Stop down everything that was started.""" self.hass.stop() diff --git a/tests/components/worldclock/test_sensor.py b/tests/components/worldclock/test_sensor.py index 3d5fc7ab5a7..783ca41afff 100644 --- a/tests/components/worldclock/test_sensor.py +++ b/tests/components/worldclock/test_sensor.py @@ -19,10 +19,7 @@ class TestWorldClockSensor(unittest.TestCase): assert setup_component(self.hass, "sensor", config) self.hass.block_till_done() - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() + self.addCleanup(self.hass.stop) def test_time(self): """Test the time at a different location.""" diff --git a/tests/components/wsdot/test_sensor.py b/tests/components/wsdot/test_sensor.py index b548c099f40..73190b6897a 100644 --- a/tests/components/wsdot/test_sensor.py +++ b/tests/components/wsdot/test_sensor.py @@ -42,8 +42,9 @@ class TestWSDOT(unittest.TestCase): CONF_TRAVEL_TIMES: [{CONF_ID: 96, CONF_NAME: "I90 EB"}], } self.entities = [] + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index 19733b045dc..d1f141582ca 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -859,8 +859,9 @@ class TestZWaveDeviceEntityValues(unittest.TestCase): self.entity_id = "mock_component.mock_node_mock_value" self.zwave_config = {"zwave": {}} self.device_config = {self.entity_id: {}} + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.stop() @@ -1204,8 +1205,9 @@ class TestZWaveServices(unittest.TestCase): self.zwave_network.state = MockNetwork.STATE_READY self.hass.bus.fire(EVENT_HOMEASSISTANT_START) self.hass.block_till_done() + self.addCleanup(self.tear_down_cleanup) - def tearDown(self): # pylint: disable=invalid-name + def tear_down_cleanup(self): """Stop everything that was started.""" self.hass.services.call("zwave", "stop_network", {}) self.hass.block_till_done()