From c33edbe5bb7a8980a8de4abea727f847ea49803a Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 8 Jun 2020 12:26:40 -0700 Subject: [PATCH] Use TestCase.addCleanup (#36560) --- tests/components/alert/test_init.py | 5 +---- tests/components/apns/test_notify.py | 3 ++- tests/components/aurora/test_binary_sensor.py | 3 ++- tests/components/blackbird/test_media_player.py | 3 ++- tests/components/bom/test_sensor.py | 5 +---- tests/components/canary/test_init.py | 3 ++- tests/components/canary/test_sensor.py | 5 +---- tests/components/coinmarketcap/test_sensor.py | 5 +---- tests/components/command_line/test_binary_sensor.py | 5 +---- tests/components/command_line/test_notify.py | 3 ++- tests/components/command_line/test_sensor.py | 5 +---- tests/components/command_line/test_switch.py | 5 +---- tests/components/configurator/test_init.py | 6 +----- tests/components/darksky/test_sensor.py | 3 ++- tests/components/darksky/test_weather.py | 3 ++- tests/components/datadog/test_init.py | 3 ++- tests/components/demo/test_geo_location.py | 5 +---- tests/components/demo/test_notify.py | 3 ++- tests/components/demo/test_remote.py | 5 +++-- tests/components/dte_energy_bridge/test_sensor.py | 5 +---- tests/components/dyson/test_climate.py | 3 ++- tests/components/dyson/test_fan.py | 6 ++++-- tests/components/dyson/test_init.py | 3 ++- tests/components/dyson/test_sensor.py | 3 ++- tests/components/dyson/test_vacuum.py | 3 ++- tests/components/efergy/test_sensor.py | 3 ++- tests/components/fail2ban/test_sensor.py | 5 +---- tests/components/fan/test_init.py | 3 ++- tests/components/feedreader/test_init.py | 5 +---- tests/components/file/test_notify.py | 3 ++- tests/components/geo_rss_events/test_sensor.py | 5 +---- tests/components/google_wifi/test_sensor.py | 10 ++-------- tests/components/group/test_init.py | 6 +----- tests/components/group/test_notify.py | 3 ++- tests/components/hddtemp/test_sensor.py | 5 +---- tests/components/history/test_init.py | 3 ++- tests/components/history_stats/test_sensor.py | 5 +---- tests/components/homeassistant/test_init.py | 6 +----- tests/components/homematic/test_notify.py | 3 ++- tests/components/imap_email_content/test_sensor.py | 5 +---- tests/components/influxdb/test_init.py | 3 ++- tests/components/kira/test_init.py | 3 ++- tests/components/kira/test_remote.py | 5 +---- tests/components/kira/test_sensor.py | 5 +---- tests/components/light/test_init.py | 4 ++-- tests/components/logbook/test_init.py | 5 +---- tests/components/logentries/test_init.py | 3 ++- tests/components/london_air/test_sensor.py | 5 +---- .../components/manual_mqtt/test_alarm_control_panel.py | 3 ++- tests/components/media_player/test_async_helpers.py | 6 ++++-- tests/components/mochad/test_light.py | 5 +---- tests/components/mochad/test_switch.py | 5 +---- tests/components/mold_indicator/test_sensor.py | 3 ++- tests/components/mqtt/test_init.py | 6 ++++-- tests/components/nsw_fuel_station/test_sensor.py | 5 +---- tests/components/nx584/test_binary_sensor.py | 3 ++- tests/components/openhardwaremonitor/test_sensor.py | 3 ++- tests/components/panel_iframe/test_init.py | 5 +---- tests/components/pilight/test_init.py | 8 +++----- tests/components/proximity/test_init.py | 5 +---- tests/components/pushbullet/test_notify.py | 3 ++- tests/components/radarr/test_sensor.py | 3 ++- tests/components/recorder/test_init.py | 3 ++- tests/components/recorder/test_models.py | 3 ++- tests/components/recorder/test_purge.py | 3 ++- tests/components/reddit/test_sensor.py | 3 ++- tests/components/remember_the_milk/test_init.py | 3 ++- tests/components/remote/test_init.py | 6 +----- tests/components/rest/test_binary_sensor.py | 10 ++-------- tests/components/rest/test_sensor.py | 10 ++-------- tests/components/rfxtrx/test_cover.py | 3 ++- tests/components/rfxtrx/test_init.py | 3 ++- tests/components/rfxtrx/test_light.py | 3 ++- tests/components/rfxtrx/test_sensor.py | 3 ++- tests/components/rfxtrx/test_switch.py | 3 ++- tests/components/ring/test_init.py | 3 ++- tests/components/scene/test_init.py | 3 ++- tests/components/script/test_init.py | 5 +++-- tests/components/season/test_sensor.py | 5 +---- tests/components/shell_command/test_init.py | 3 ++- tests/components/sigfox/test_sensor.py | 5 +---- tests/components/sleepiq/test_binary_sensor.py | 3 ++- tests/components/sleepiq/test_init.py | 3 ++- tests/components/sleepiq/test_sensor.py | 3 ++- tests/components/smtp/test_notify.py | 3 ++- tests/components/splunk/test_init.py | 3 ++- tests/components/statsd/test_init.py | 3 ++- tests/components/switch/test_init.py | 6 +----- tests/components/time_date/test_sensor.py | 3 ++- tests/components/transport_nsw/test_sensor.py | 5 +---- tests/components/uk_transport/test_sensor.py | 5 +---- tests/components/universal/test_media_player.py | 3 ++- tests/components/uptime/test_sensor.py | 5 +---- tests/components/uvc/test_camera.py | 5 +---- tests/components/vultr/test_binary_sensor.py | 3 ++- tests/components/vultr/test_init.py | 3 ++- tests/components/vultr/test_sensor.py | 5 +---- tests/components/vultr/test_switch.py | 3 ++- tests/components/wake_on_lan/test_switch.py | 5 +---- tests/components/weather/test_weather.py | 3 ++- tests/components/worldclock/test_sensor.py | 5 +---- tests/components/wsdot/test_sensor.py | 3 ++- tests/components/zwave/test_init.py | 6 ++++-- 103 files changed, 179 insertions(+), 254 deletions(-) diff --git a/tests/components/alert/test_init.py b/tests/components/alert/test_init.py index 96c36a87ed..ea029dc8a2 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 5c69e19435..6c27299de5 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 f90c1e2bcc..ea385d5697 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 b090368a4c..316ed681fa 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 8c647bbf6c..49cdb3e6ee 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 a3f6fbd7e2..0cfbfd56de 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 5a4a82ccc5..d7d16fa5f8 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 f53a92a3d8..4d1fb31da9 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 33c28b7d65..90871faaf7 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 f20011d448..ecdb5af91d 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 bbf69dc73a..ff3110f8e2 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 ab5d0044f7..5c4a1aa336 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 b572609c5a..9d696ab5f8 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 9a48e4f1cc..be1e984945 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 9f43534d7c..1a2a2e156d 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 71b2af33fd..9ba64bb43f 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 0ba3a35b89..dd4c2022c5 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 7c7b7fa0aa..07b6d968c8 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 7ea31fbeb6..fa87213768 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 34f0a0a28c..38d712468c 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 af17d1f0ab..2d769231f1 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 d4db605196..807cf3565e 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 37cc69b676..d2c36beb7d 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 92bd3bba9a..d15826863b 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 fc801cbe64..0ff1966580 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 252669233e..7d1d928cef 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 b164cc93f2..fa78c9b1bb 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 f27a3ff8ab..134a5976ba 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 823bdf6eb6..1983cb5ab8 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 e4ae125949..d7f380cf6d 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 9f7cdd3faa..61e4ab1e7d 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 69db8de184..ff3ec0429f 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 c4d98ad37c..ff5f3a30f7 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 0925b318c9..b120cf2cea 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 84315afb47..4062d737ea 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 ba0e0b9f1c..b47eca9f05 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 900af4988e..25cca7615a 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 b9309d70d6..3419aea06a 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 411be41eb3..e1bd2f4f22 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 ee39bac51e..3a0c006d15 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 bdfd41eae8..cdbb39ba3c 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 8656ac2326..b57d8c9761 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 b1ac7ea12f..c946823474 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 2fae36dc67..21572a8735 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 2fa22cd81d..b46be5c926 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 e96bb876b6..91b90426d3 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 f850a7dd62..2d7b7ee6c2 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 f596750ea7..066fc357a5 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 a23382d9f7..996811224c 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 ac0d70bded..12414801a5 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 2dd385f025..eb9cf047d0 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 699edfe899..66f84c16fe 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 5f3b223bf6..423c728ff7 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 94961ebfe7..475f337f53 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 861aa155f4..d4e10ff512 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 a02a4fbe3a..a9f3e6df7f 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 db44216c53..6c8776f740 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 b38f3c4b1f..7d42c4d03d 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 53b1ec3a94..5c2acc0d8f 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 d3b6f9274e..55aca3223f 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 930d9261f9..b0fb55e152 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 0e76e99e72..96575f8115 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 1931a367ee..a325f78d83 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 276194b5d6..f2eb28b3d0 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 4ec08c432b..ac59ca5e2d 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 33c7fae76b..faa3679f49 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 2bba18f005..1c9438c602 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 031131276f..eb47d365f8 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 762c1705d7..4d893a2ef6 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 77d88f083e..90a8b8d361 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 d85ea5cf6f..9ecbcda340 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 6b75cc92fc..669ec24efc 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 a5230cc5f3..1a8ee94d9a 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 e258ebb9aa..fa713a024c 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 66da197aae..cc1a6008fa 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 39d2c63ffd..4ad056150d 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 bff88d8e66..7f8308d3e2 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 8dbe43a25f..7e5d77a855 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 279291d6da..8918099405 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 8743ab27bd..76f81ea72d 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 c4af07b579..923392bbaf 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 fbafe8aad7..ab51a08d4c 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 9c1c0972fa..850d42763d 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 d94cd7e406..3e5cbc657e 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 f74d47a21c..d99ee82d4e 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 256c78af50..2822e40440 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 4c7e9d29fe..9564de85a9 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 6605d19d46..5853e5faee 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 80a081cd52..c5e8ccecc4 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 0d12589372..d2aa8fb938 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 7385592fe9..81cfa7ae8a 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 bf780d3392..b50906649f 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 111114d8ac..08758741b9 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 22df898f00..35e6c82ded 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 609cdbf6a9..af99dc12c5 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 6035ac547a..9ce96d7969 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 1ced0fec82..8e9cb606d1 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 594617bdfd..77eb1e7a8c 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 d99bc1ccb4..6db8018593 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 d026cd6ee8..10161a0d63 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 3d5fc7ab5a..783ca41aff 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 b548c099f4..73190b6897 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 19733b045d..d1f141582c 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()