From 906385172abd0c13b35523de583a10b545d98930 Mon Sep 17 00:00:00 2001
From: Franck Nijhof <git@frenck.dev>
Date: Sun, 5 Apr 2020 00:26:08 +0200
Subject: [PATCH] String formatting improvements for tests (#33663)

---
 tests/components/alexa/__init__.py            |  2 +-
 tests/components/bom/test_sensor.py           |  4 +--
 tests/components/broadlink/test_init.py       |  2 +-
 tests/components/command_line/test_cover.py   |  8 ++---
 tests/components/command_line/test_notify.py  |  4 +--
 tests/components/command_line/test_switch.py  | 22 ++++++------
 .../components/config/test_config_entries.py  | 17 ++++------
 tests/components/darksky/test_sensor.py       |  2 +-
 tests/components/datadog/test_init.py         |  9 ++---
 tests/components/demo/test_vacuum.py          | 12 +++----
 tests/components/device_tracker/test_init.py  |  2 +-
 tests/components/dialogflow/test_init.py      | 34 +++++++++----------
 tests/components/efergy/test_sensor.py        | 14 ++++----
 tests/components/history/test_init.py         | 10 +++---
 .../components/image_processing/test_init.py  | 12 ++-----
 tests/components/influxdb/test_init.py        | 26 +++++++-------
 tests/components/locative/test_init.py        | 12 +++----
 tests/components/logbook/test_init.py         | 18 +++++-----
 tests/components/mobile_app/test_entity.py    |  6 ++--
 tests/components/mqtt_room/test_sensor.py     |  6 ++--
 .../openalpr_local/test_image_processing.py   |  4 +--
 tests/components/ps4/test_media_player.py     |  4 +--
 tests/components/python_script/test_init.py   |  2 +-
 tests/components/recorder/test_init.py        |  2 +-
 tests/components/roku/__init__.py             |  2 +-
 tests/components/scene/test_init.py           |  6 ++--
 tests/components/script/test_init.py          |  2 +-
 tests/components/shell_command/test_init.py   |  8 ++---
 tests/components/shopping_list/test_init.py   | 10 +++---
 tests/components/sleepiq/test_init.py         |  6 ++--
 tests/components/switch/test_init.py          |  2 +-
 tests/components/tplink/test_init.py          |  4 +--
 tests/components/traccar/test_init.py         | 10 +++---
 33 files changed, 129 insertions(+), 155 deletions(-)

diff --git a/tests/components/alexa/__init__.py b/tests/components/alexa/__init__.py
index 04f90476c57..a3bc548ee28 100644
--- a/tests/components/alexa/__init__.py
+++ b/tests/components/alexa/__init__.py
@@ -205,4 +205,4 @@ class ReportedProperties:
                 assert prop["value"] == value
                 return prop
 
-        assert False, "property %s:%s not in %r" % (namespace, name, self.properties)
+        assert False, f"property {namespace}:{name} not in {self.properties!r}"
diff --git a/tests/components/bom/test_sensor.py b/tests/components/bom/test_sensor.py
index 6d452f7a6a3..7a9daa26c2b 100644
--- a/tests/components/bom/test_sensor.py
+++ b/tests/components/bom/test_sensor.py
@@ -50,7 +50,7 @@ def mocked_requests(*args, **kwargs):
     if re.match(r"^/fwo/[\w]+/[\w.]+\.json", url.path):
         return MockResponse(json.loads(load_fixture("bom_weather.json")), 200)
 
-    raise NotImplementedError("Unknown route {}".format(url.path))
+    raise NotImplementedError(f"Unknown route {url.path}")
 
 
 class TestBOMWeatherSensor(unittest.TestCase):
@@ -78,7 +78,7 @@ class TestBOMWeatherSensor(unittest.TestCase):
         ]
 
         for entity_id in fake_entities:
-            state = self.hass.states.get("sensor.{}".format(entity_id))
+            state = self.hass.states.get(f"sensor.{entity_id}")
             assert state is not None
 
     @patch("requests.get", side_effect=mocked_requests)
diff --git a/tests/components/broadlink/test_init.py b/tests/components/broadlink/test_init.py
index d4e3c993cd0..1bdad193f52 100644
--- a/tests/components/broadlink/test_init.py
+++ b/tests/components/broadlink/test_init.py
@@ -69,7 +69,7 @@ async def test_learn(hass):
 
         assert mock_create.call_count == 1
         assert mock_create.call_args == call(
-            "Received packet is: {}".format(DUMMY_IR_PACKET), title="Broadlink switch"
+            f"Received packet is: {DUMMY_IR_PACKET}", title="Broadlink switch"
         )
 
 
diff --git a/tests/components/command_line/test_cover.py b/tests/components/command_line/test_cover.py
index 1cd76581bdc..fc359d49b26 100644
--- a/tests/components/command_line/test_cover.py
+++ b/tests/components/command_line/test_cover.py
@@ -54,10 +54,10 @@ async def test_state_value(hass):
     with tempfile.TemporaryDirectory() as tempdirname:
         path = os.path.join(tempdirname, "cover_status")
         test_cover = {
-            "command_state": "cat {}".format(path),
-            "command_open": "echo 1 > {}".format(path),
-            "command_close": "echo 1 > {}".format(path),
-            "command_stop": "echo 0 > {}".format(path),
+            "command_state": f"cat {path}",
+            "command_open": f"echo 1 > {path}",
+            "command_close": f"echo 1 > {path}",
+            "command_stop": f"echo 0 > {path}",
             "value_template": "{{ value }}",
         }
         assert (
diff --git a/tests/components/command_line/test_notify.py b/tests/components/command_line/test_notify.py
index 8bdc4ba0a01..cd937115868 100644
--- a/tests/components/command_line/test_notify.py
+++ b/tests/components/command_line/test_notify.py
@@ -57,7 +57,7 @@ class TestCommandLine(unittest.TestCase):
                         "notify": {
                             "name": "test",
                             "platform": "command_line",
-                            "command": "echo $(cat) > {}".format(filename),
+                            "command": f"echo $(cat) > {filename}",
                         }
                     },
                 )
@@ -69,7 +69,7 @@ class TestCommandLine(unittest.TestCase):
 
             with open(filename) as fil:
                 # the echo command adds a line break
-                assert fil.read() == "{}\n".format(message)
+                assert fil.read() == f"{message}\n"
 
     @patch("homeassistant.components.command_line.notify._LOGGER.error")
     def test_error_for_none_zero_exit_code(self, mock_error):
diff --git a/tests/components/command_line/test_switch.py b/tests/components/command_line/test_switch.py
index 497fb0c2523..acdb5b23b10 100644
--- a/tests/components/command_line/test_switch.py
+++ b/tests/components/command_line/test_switch.py
@@ -30,8 +30,8 @@ class TestCommandSwitch(unittest.TestCase):
         with tempfile.TemporaryDirectory() as tempdirname:
             path = os.path.join(tempdirname, "switch_status")
             test_switch = {
-                "command_on": "echo 1 > {}".format(path),
-                "command_off": "echo 0 > {}".format(path),
+                "command_on": f"echo 1 > {path}",
+                "command_off": f"echo 0 > {path}",
             }
             assert setup_component(
                 self.hass,
@@ -64,9 +64,9 @@ class TestCommandSwitch(unittest.TestCase):
         with tempfile.TemporaryDirectory() as tempdirname:
             path = os.path.join(tempdirname, "switch_status")
             test_switch = {
-                "command_state": "cat {}".format(path),
-                "command_on": "echo 1 > {}".format(path),
-                "command_off": "echo 0 > {}".format(path),
+                "command_state": f"cat {path}",
+                "command_on": f"echo 1 > {path}",
+                "command_off": f"echo 0 > {path}",
                 "value_template": '{{ value=="1" }}',
             }
             assert setup_component(
@@ -102,9 +102,9 @@ class TestCommandSwitch(unittest.TestCase):
             oncmd = json.dumps({"status": "ok"})
             offcmd = json.dumps({"status": "nope"})
             test_switch = {
-                "command_state": "cat {}".format(path),
-                "command_on": "echo '{}' > {}".format(oncmd, path),
-                "command_off": "echo '{}' > {}".format(offcmd, path),
+                "command_state": f"cat {path}",
+                "command_on": f"echo '{oncmd}' > {path}",
+                "command_off": f"echo '{offcmd}' > {path}",
                 "value_template": '{{ value_json.status=="ok" }}',
             }
             assert setup_component(
@@ -138,9 +138,9 @@ class TestCommandSwitch(unittest.TestCase):
         with tempfile.TemporaryDirectory() as tempdirname:
             path = os.path.join(tempdirname, "switch_status")
             test_switch = {
-                "command_state": "cat {}".format(path),
-                "command_on": "echo 1 > {}".format(path),
-                "command_off": "echo 0 > {}".format(path),
+                "command_state": f"cat {path}",
+                "command_on": f"echo 1 > {path}",
+                "command_off": f"echo 0 > {path}",
             }
             assert setup_component(
                 self.hass,
diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py
index ccd41eeb3a5..d944ebb6eb6 100644
--- a/tests/components/config/test_config_entries.py
+++ b/tests/components/config/test_config_entries.py
@@ -97,9 +97,7 @@ async def test_remove_entry(hass, client):
     """Test removing an entry via the API."""
     entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
     entry.add_to_hass(hass)
-    resp = await client.delete(
-        "/api/config/config_entries/entry/{}".format(entry.entry_id)
-    )
+    resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}")
     assert resp.status == 200
     data = await resp.json()
     assert data == {"require_restart": True}
@@ -111,9 +109,7 @@ async def test_remove_entry_unauth(hass, client, hass_admin_user):
     hass_admin_user.groups = []
     entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
     entry.add_to_hass(hass)
-    resp = await client.delete(
-        "/api/config/config_entries/entry/{}".format(entry.entry_id)
-    )
+    resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}")
     assert resp.status == 401
     assert len(hass.config_entries.async_entries()) == 1
 
@@ -124,7 +120,7 @@ async def test_available_flows(hass, client):
         resp = await client.get("/api/config/config_entries/flow_handlers")
         assert resp.status == 200
         data = await resp.json()
-        assert set(data) == set(["hello", "world"])
+        assert set(data) == {"hello", "world"}
 
 
 ############################
@@ -294,7 +290,7 @@ async def test_two_step_flow(hass, client):
 
     with patch.dict(HANDLERS, {"test": TestFlow}):
         resp = await client.post(
-            "/api/config/config_entries/flow/{}".format(flow_id),
+            f"/api/config/config_entries/flow/{flow_id}",
             json={"user_title": "user-title"},
         )
         assert resp.status == 200
@@ -352,8 +348,7 @@ async def test_continue_flow_unauth(hass, client, hass_admin_user):
     hass_admin_user.groups = []
 
     resp = await client.post(
-        "/api/config/config_entries/flow/{}".format(flow_id),
-        json={"user_title": "user-title"},
+        f"/api/config/config_entries/flow/{flow_id}", json={"user_title": "user-title"},
     )
     assert resp.status == 401
 
@@ -559,7 +554,7 @@ async def test_two_step_options_flow(hass, client):
 
     with patch.dict(HANDLERS, {"test": TestFlow}):
         resp = await client.post(
-            "/api/config/config_entries/options/flow/{}".format(flow_id),
+            f"/api/config/config_entries/options/flow/{flow_id}",
             json={"enabled": True},
         )
         assert resp.status == 200
diff --git a/tests/components/darksky/test_sensor.py b/tests/components/darksky/test_sensor.py
index eff06e3bf7d..2163a809b5e 100644
--- a/tests/components/darksky/test_sensor.py
+++ b/tests/components/darksky/test_sensor.py
@@ -156,7 +156,7 @@ class TestDarkSkySetup(unittest.TestCase):
         url = "https://api.darksky.net/forecast/{}/{},{}?units=auto".format(
             self.key, str(self.lat), str(self.lon)
         )
-        msg = "400 Client Error: Bad Request for url: {}".format(url)
+        msg = f"400 Client Error: Bad Request for url: {url}"
         mock_get_forecast.side_effect = HTTPError(msg)
 
         response = darksky.setup_platform(
diff --git a/tests/components/datadog/test_init.py b/tests/components/datadog/test_init.py
index fdaec26204d..71b2af33fd3 100644
--- a/tests/components/datadog/test_init.py
+++ b/tests/components/datadog/test_init.py
@@ -150,19 +150,16 @@ class TestDatadog(unittest.TestCase):
                 mock_client.gauge.assert_has_calls(
                     [
                         mock.call(
-                            "ha.sensor.{}".format(attribute),
+                            f"ha.sensor.{attribute}",
                             value,
                             sample_rate=1,
-                            tags=["entity:{}".format(state.entity_id)],
+                            tags=[f"entity:{state.entity_id}"],
                         )
                     ]
                 )
 
             assert mock_client.gauge.call_args == mock.call(
-                "ha.sensor",
-                out,
-                sample_rate=1,
-                tags=["entity:{}".format(state.entity_id)],
+                "ha.sensor", out, sample_rate=1, tags=[f"entity:{state.entity_id}"],
             )
 
             mock_client.gauge.reset_mock()
diff --git a/tests/components/demo/test_vacuum.py b/tests/components/demo/test_vacuum.py
index 79f9d361169..2bd39bf7cb3 100644
--- a/tests/components/demo/test_vacuum.py
+++ b/tests/components/demo/test_vacuum.py
@@ -39,12 +39,12 @@ from homeassistant.setup import setup_component
 from tests.common import get_test_home_assistant, mock_service
 from tests.components.vacuum import common
 
-ENTITY_VACUUM_BASIC = "{}.{}".format(DOMAIN, DEMO_VACUUM_BASIC).lower()
-ENTITY_VACUUM_COMPLETE = "{}.{}".format(DOMAIN, DEMO_VACUUM_COMPLETE).lower()
-ENTITY_VACUUM_MINIMAL = "{}.{}".format(DOMAIN, DEMO_VACUUM_MINIMAL).lower()
-ENTITY_VACUUM_MOST = "{}.{}".format(DOMAIN, DEMO_VACUUM_MOST).lower()
-ENTITY_VACUUM_NONE = "{}.{}".format(DOMAIN, DEMO_VACUUM_NONE).lower()
-ENTITY_VACUUM_STATE = "{}.{}".format(DOMAIN, DEMO_VACUUM_STATE).lower()
+ENTITY_VACUUM_BASIC = f"{DOMAIN}.{DEMO_VACUUM_BASIC}".lower()
+ENTITY_VACUUM_COMPLETE = f"{DOMAIN}.{DEMO_VACUUM_COMPLETE}".lower()
+ENTITY_VACUUM_MINIMAL = f"{DOMAIN}.{DEMO_VACUUM_MINIMAL}".lower()
+ENTITY_VACUUM_MOST = f"{DOMAIN}.{DEMO_VACUUM_MOST}".lower()
+ENTITY_VACUUM_NONE = f"{DOMAIN}.{DEMO_VACUUM_NONE}".lower()
+ENTITY_VACUUM_STATE = f"{DOMAIN}.{DEMO_VACUUM_STATE}".lower()
 
 
 class TestVacuumDemo(unittest.TestCase):
diff --git a/tests/components/device_tracker/test_init.py b/tests/components/device_tracker/test_init.py
index 1a21ad4a7a4..8ecc341d4d2 100644
--- a/tests/components/device_tracker/test_init.py
+++ b/tests/components/device_tracker/test_init.py
@@ -548,7 +548,7 @@ async def test_async_added_to_hass(hass):
 
     for key, val in attr.items():
         atr = state.attributes.get(key)
-        assert atr == val, "{}={} expected: {}".format(key, atr, val)
+        assert atr == val, f"{key}={atr} expected: {val}"
 
 
 async def test_bad_platform(hass):
diff --git a/tests/components/dialogflow/test_init.py b/tests/components/dialogflow/test_init.py
index aaec1ee67cf..70a75e68c6f 100644
--- a/tests/components/dialogflow/test_init.py
+++ b/tests/components/dialogflow/test_init.py
@@ -165,7 +165,7 @@ async def test_intent_action_incomplete_v1(fixture):
     data["result"]["actionIncomplete"] = True
 
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     assert "" == await response.text()
@@ -178,7 +178,7 @@ async def test_intent_action_incomplete_v2(fixture):
     data["queryResult"]["allRequiredParamsPresent"] = False
 
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     assert "" == await response.text()
@@ -220,7 +220,7 @@ async def test_intent_slot_filling_v1(fixture):
     data["result"]["metadata"].update(webhookForSlotFillingUsed="true")
 
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     assert "" == await response.text()
@@ -231,7 +231,7 @@ async def test_intent_request_with_parameters_v1(fixture):
     mock_client, webhook_id = fixture
     data = Data.v1
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("speech")
@@ -243,7 +243,7 @@ async def test_intent_request_with_parameters_v2(fixture):
     mock_client, webhook_id = fixture
     data = Data.v2
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("fulfillmentText")
@@ -256,7 +256,7 @@ async def test_intent_request_with_parameters_but_empty_v1(fixture):
     data = Data.v1
     data["result"].update(parameters={"ZodiacSign": ""})
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("speech")
@@ -269,7 +269,7 @@ async def test_intent_request_with_parameters_but_empty_v2(fixture):
     data = Data.v2
     data["queryResult"].update(parameters={"ZodiacSign": ""})
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("fulfillmentText")
@@ -288,7 +288,7 @@ async def test_intent_request_without_slots_v1(hass, fixture):
     )
 
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("speech")
@@ -299,7 +299,7 @@ async def test_intent_request_without_slots_v1(hass, fixture):
     hass.states.async_set("device_tracker.anne_therese", "home")
 
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("speech")
@@ -318,7 +318,7 @@ async def test_intent_request_without_slots_v2(hass, fixture):
     )
 
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("fulfillmentText")
@@ -329,7 +329,7 @@ async def test_intent_request_without_slots_v2(hass, fixture):
     hass.states.async_set("device_tracker.anne_therese", "home")
 
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("fulfillmentText")
@@ -347,7 +347,7 @@ async def test_intent_request_calling_service_v1(fixture, calls):
     data["result"]["action"] = "CallServiceIntent"
     call_count = len(calls)
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     assert call_count + 1 == len(calls)
@@ -369,7 +369,7 @@ async def test_intent_request_calling_service_v2(fixture, calls):
     data["queryResult"]["action"] = "CallServiceIntent"
     call_count = len(calls)
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     assert call_count + 1 == len(calls)
@@ -387,7 +387,7 @@ async def test_intent_with_no_action_v1(fixture):
     del data["result"]["action"]
     assert "action" not in data["result"]
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("speech")
@@ -401,7 +401,7 @@ async def test_intent_with_no_action_v2(fixture):
     del data["queryResult"]["action"]
     assert "action" not in data["queryResult"]
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("fulfillmentText")
@@ -414,7 +414,7 @@ async def test_intent_with_unknown_action_v1(fixture):
     data = Data.v1
     data["result"]["action"] = "unknown"
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("speech")
@@ -427,7 +427,7 @@ async def test_intent_with_unknown_action_v2(fixture):
     data = Data.v2
     data["queryResult"]["action"] = "unknown"
     response = await mock_client.post(
-        "/api/webhook/{}".format(webhook_id), data=json.dumps(data)
+        f"/api/webhook/{webhook_id}", data=json.dumps(data)
     )
     assert 200 == response.status
     text = (await response.json()).get("fulfillmentText")
diff --git a/tests/components/efergy/test_sensor.py b/tests/components/efergy/test_sensor.py
index 18a00005dd5..166325ee242 100644
--- a/tests/components/efergy/test_sensor.py
+++ b/tests/components/efergy/test_sensor.py
@@ -35,27 +35,25 @@ def mock_responses(mock):
     """Mock responses for Efergy."""
     base_url = "https://engage.efergy.com/mobile_proxy/"
     mock.get(
-        "{}getInstant?token={}".format(base_url, token),
-        text=load_fixture("efergy_instant.json"),
+        f"{base_url}getInstant?token={token}", text=load_fixture("efergy_instant.json"),
     )
     mock.get(
-        "{}getEnergy?token={}&offset=300&period=day".format(base_url, token),
+        f"{base_url}getEnergy?token={token}&offset=300&period=day",
         text=load_fixture("efergy_energy.json"),
     )
     mock.get(
-        "{}getBudget?token={}".format(base_url, token),
-        text=load_fixture("efergy_budget.json"),
+        f"{base_url}getBudget?token={token}", text=load_fixture("efergy_budget.json"),
     )
     mock.get(
-        "{}getCost?token={}&offset=300&period=day".format(base_url, token),
+        f"{base_url}getCost?token={token}&offset=300&period=day",
         text=load_fixture("efergy_cost.json"),
     )
     mock.get(
-        "{}getCurrentValuesSummary?token={}".format(base_url, token),
+        f"{base_url}getCurrentValuesSummary?token={token}",
         text=load_fixture("efergy_current_values_single.json"),
     )
     mock.get(
-        "{}getCurrentValuesSummary?token={}".format(base_url, multi_sensor_token),
+        f"{base_url}getCurrentValuesSummary?token={multi_sensor_token}",
         text=load_fixture("efergy_current_values_multi.json"),
     )
 
diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py
index 64b438a29fc..b2687b2bd50 100644
--- a/tests/components/history/test_init.py
+++ b/tests/components/history/test_init.py
@@ -66,7 +66,7 @@ class TestComponentHistory(unittest.TestCase):
             for i in range(5):
                 state = ha.State(
                     "test.point_in_time_{}".format(i % 5),
-                    "State {}".format(i),
+                    f"State {i}",
                     {"attribute_test": i},
                 )
 
@@ -83,7 +83,7 @@ class TestComponentHistory(unittest.TestCase):
             for i in range(5):
                 state = ha.State(
                     "test.point_in_time_{}".format(i % 5),
-                    "State {}".format(i),
+                    f"State {i}",
                     {"attribute_test": i},
                 )
 
@@ -677,9 +677,7 @@ async def test_fetch_period_api(hass, hass_client):
     await async_setup_component(hass, "history", {})
     await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
     client = await hass_client()
-    response = await client.get(
-        "/api/history/period/{}".format(dt_util.utcnow().isoformat())
-    )
+    response = await client.get(f"/api/history/period/{dt_util.utcnow().isoformat()}")
     assert response.status == 200
 
 
@@ -699,7 +697,7 @@ async def test_fetch_period_api_with_include_order(hass, hass_client):
     await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
     client = await hass_client()
     response = await client.get(
-        "/api/history/period/{}".format(dt_util.utcnow().isoformat()),
+        f"/api/history/period/{dt_util.utcnow().isoformat()}",
         params={"filter_entity_id": "non.existing,something.else"},
     )
     assert response.status == 200
diff --git a/tests/components/image_processing/test_init.py b/tests/components/image_processing/test_init.py
index 39cbb8d583e..95a6d65a9fb 100644
--- a/tests/components/image_processing/test_init.py
+++ b/tests/components/image_processing/test_init.py
@@ -62,9 +62,7 @@ class TestImageProcessing:
         setup_component(self.hass, ip.DOMAIN, config)
 
         state = self.hass.states.get("camera.demo_camera")
-        self.url = "{0}{1}".format(
-            self.hass.config.api.base_url, state.attributes.get(ATTR_ENTITY_PICTURE)
-        )
+        self.url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
 
     def teardown_method(self):
         """Stop everything that was started."""
@@ -120,9 +118,7 @@ class TestImageProcessingAlpr:
             setup_component(self.hass, ip.DOMAIN, config)
 
         state = self.hass.states.get("camera.demo_camera")
-        self.url = "{0}{1}".format(
-            self.hass.config.api.base_url, state.attributes.get(ATTR_ENTITY_PICTURE)
-        )
+        self.url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
 
         self.alpr_events = []
 
@@ -227,9 +223,7 @@ class TestImageProcessingFace:
             setup_component(self.hass, ip.DOMAIN, config)
 
         state = self.hass.states.get("camera.demo_camera")
-        self.url = "{0}{1}".format(
-            self.hass.config.api.base_url, state.attributes.get(ATTR_ENTITY_PICTURE)
-        )
+        self.url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
 
         self.face_events = []
 
diff --git a/tests/components/influxdb/test_init.py b/tests/components/influxdb/test_init.py
index 2bb9faad8e5..958bcc9d975 100644
--- a/tests/components/influxdb/test_init.py
+++ b/tests/components/influxdb/test_init.py
@@ -252,14 +252,14 @@ class TestInfluxDB(unittest.TestCase):
             state = mock.MagicMock(
                 state=1,
                 domain="fake",
-                entity_id="fake.{}".format(entity_id),
+                entity_id=f"fake.{entity_id}",
                 object_id=entity_id,
                 attributes={},
             )
             event = mock.MagicMock(data={"new_state": state}, time_fired=12345)
             body = [
                 {
-                    "measurement": "fake.{}".format(entity_id),
+                    "measurement": f"fake.{entity_id}",
                     "tags": {"domain": "fake", "entity_id": entity_id},
                     "time": 12345,
                     "fields": {"value": 1},
@@ -284,14 +284,14 @@ class TestInfluxDB(unittest.TestCase):
             state = mock.MagicMock(
                 state=1,
                 domain=domain,
-                entity_id="{}.something".format(domain),
+                entity_id=f"{domain}.something",
                 object_id="something",
                 attributes={},
             )
             event = mock.MagicMock(data={"new_state": state}, time_fired=12345)
             body = [
                 {
-                    "measurement": "{}.something".format(domain),
+                    "measurement": f"{domain}.something",
                     "tags": {"domain": domain, "entity_id": "something"},
                     "time": 12345,
                     "fields": {"value": 1},
@@ -326,14 +326,14 @@ class TestInfluxDB(unittest.TestCase):
             state = mock.MagicMock(
                 state=1,
                 domain="fake",
-                entity_id="fake.{}".format(entity_id),
+                entity_id=f"fake.{entity_id}",
                 object_id=entity_id,
                 attributes={},
             )
             event = mock.MagicMock(data={"new_state": state}, time_fired=12345)
             body = [
                 {
-                    "measurement": "fake.{}".format(entity_id),
+                    "measurement": f"fake.{entity_id}",
                     "tags": {"domain": "fake", "entity_id": entity_id},
                     "time": 12345,
                     "fields": {"value": 1},
@@ -368,14 +368,14 @@ class TestInfluxDB(unittest.TestCase):
             state = mock.MagicMock(
                 state=1,
                 domain=domain,
-                entity_id="{}.something".format(domain),
+                entity_id=f"{domain}.something",
                 object_id="something",
                 attributes={},
             )
             event = mock.MagicMock(data={"new_state": state}, time_fired=12345)
             body = [
                 {
-                    "measurement": "{}.something".format(domain),
+                    "measurement": f"{domain}.something",
                     "tags": {"domain": domain, "entity_id": "something"},
                     "time": 12345,
                     "fields": {"value": 1},
@@ -410,14 +410,14 @@ class TestInfluxDB(unittest.TestCase):
             state = mock.MagicMock(
                 state=1,
                 domain=domain,
-                entity_id="{}.something".format(domain),
+                entity_id=f"{domain}.something",
                 object_id="something",
                 attributes={},
             )
             event = mock.MagicMock(data={"new_state": state}, time_fired=12345)
             body = [
                 {
-                    "measurement": "{}.something".format(domain),
+                    "measurement": f"{domain}.something",
                     "tags": {"domain": domain, "entity_id": "something"},
                     "time": 12345,
                     "fields": {"value": 1},
@@ -438,14 +438,14 @@ class TestInfluxDB(unittest.TestCase):
             state = mock.MagicMock(
                 state=1,
                 domain="other",
-                entity_id="other.{}".format(entity_id),
+                entity_id=f"other.{entity_id}",
                 object_id=entity_id,
                 attributes={},
             )
             event = mock.MagicMock(data={"new_state": state}, time_fired=12345)
             body = [
                 {
-                    "measurement": "other.{}".format(entity_id),
+                    "measurement": f"other.{entity_id}",
                     "tags": {"domain": "other", "entity_id": entity_id},
                     "time": 12345,
                     "fields": {"value": 1},
@@ -532,7 +532,7 @@ class TestInfluxDB(unittest.TestCase):
             state = mock.MagicMock(
                 state=1,
                 domain="fake",
-                entity_id="fake.{}".format(entity_id),
+                entity_id=f"fake.{entity_id}",
                 object_id=entity_id,
                 attributes={},
             )
diff --git a/tests/components/locative/test_init.py b/tests/components/locative/test_init.py
index 009a3d469c5..63ef2e9f5f8 100644
--- a/tests/components/locative/test_init.py
+++ b/tests/components/locative/test_init.py
@@ -48,7 +48,7 @@ async def webhook_id(hass, locative_client):
 
 async def test_missing_data(locative_client, webhook_id):
     """Test missing data."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
 
     data = {
         "latitude": 1.0,
@@ -108,7 +108,7 @@ async def test_missing_data(locative_client, webhook_id):
 
 async def test_enter_and_exit(hass, locative_client, webhook_id):
     """Test when there is a known zone."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
 
     data = {
         "latitude": 40.7855,
@@ -177,7 +177,7 @@ async def test_enter_and_exit(hass, locative_client, webhook_id):
 
 async def test_exit_after_enter(hass, locative_client, webhook_id):
     """Test when an exit message comes after an enter message."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
 
     data = {
         "latitude": 40.7855,
@@ -219,7 +219,7 @@ async def test_exit_after_enter(hass, locative_client, webhook_id):
 
 async def test_exit_first(hass, locative_client, webhook_id):
     """Test when an exit message is sent first on a new device."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
 
     data = {
         "latitude": 40.7855,
@@ -240,7 +240,7 @@ async def test_exit_first(hass, locative_client, webhook_id):
 
 async def test_two_devices(hass, locative_client, webhook_id):
     """Test updating two different devices."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
 
     data_device_1 = {
         "latitude": 40.7855,
@@ -283,7 +283,7 @@ async def test_two_devices(hass, locative_client, webhook_id):
 )
 async def test_load_unload_entry(hass, locative_client, webhook_id):
     """Test that the appropriate dispatch signals are added and removed."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
 
     data = {
         "latitude": 40.7855,
diff --git a/tests/components/logbook/test_init.py b/tests/components/logbook/test_init.py
index cc07d6cf40f..2045aeb1a5a 100644
--- a/tests/components/logbook/test_init.py
+++ b/tests/components/logbook/test_init.py
@@ -1274,7 +1274,7 @@ async def test_logbook_view(hass, hass_client):
     await async_setup_component(hass, "logbook", {})
     await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
     client = await hass_client()
-    response = await client.get("/api/logbook/{}".format(dt_util.utcnow().isoformat()))
+    response = await client.get(f"/api/logbook/{dt_util.utcnow().isoformat()}")
     assert response.status == 200
 
 
@@ -1301,7 +1301,7 @@ async def test_logbook_view_period_entity(hass, hass_client):
     start_date = datetime(start.year, start.month, start.day)
 
     # Test today entries without filters
-    response = await client.get("/api/logbook/{}".format(start_date.isoformat()))
+    response = await client.get(f"/api/logbook/{start_date.isoformat()}")
     assert response.status == 200
     json = await response.json()
     assert len(json) == 2
@@ -1309,9 +1309,7 @@ async def test_logbook_view_period_entity(hass, hass_client):
     assert json[1]["entity_id"] == entity_id_second
 
     # Test today entries with filter by period
-    response = await client.get(
-        "/api/logbook/{}?period=1".format(start_date.isoformat())
-    )
+    response = await client.get(f"/api/logbook/{start_date.isoformat()}?period=1")
     assert response.status == 200
     json = await response.json()
     assert len(json) == 2
@@ -1320,7 +1318,7 @@ async def test_logbook_view_period_entity(hass, hass_client):
 
     # Test today entries with filter by entity_id
     response = await client.get(
-        "/api/logbook/{}?entity=switch.test".format(start_date.isoformat())
+        f"/api/logbook/{start_date.isoformat()}?entity=switch.test"
     )
     assert response.status == 200
     json = await response.json()
@@ -1329,7 +1327,7 @@ async def test_logbook_view_period_entity(hass, hass_client):
 
     # Test entries for 3 days with filter by entity_id
     response = await client.get(
-        "/api/logbook/{}?period=3&entity=switch.test".format(start_date.isoformat())
+        f"/api/logbook/{start_date.isoformat()}?period=3&entity=switch.test"
     )
     assert response.status == 200
     json = await response.json()
@@ -1341,14 +1339,14 @@ async def test_logbook_view_period_entity(hass, hass_client):
     start_date = datetime(start.year, start.month, start.day)
 
     # Test tomorrow entries without filters
-    response = await client.get("/api/logbook/{}".format(start_date.isoformat()))
+    response = await client.get(f"/api/logbook/{start_date.isoformat()}")
     assert response.status == 200
     json = await response.json()
     assert len(json) == 0
 
     # Test tomorrow entries with filter by entity_id
     response = await client.get(
-        "/api/logbook/{}?entity=switch.test".format(start_date.isoformat())
+        f"/api/logbook/{start_date.isoformat()}?entity=switch.test"
     )
     assert response.status == 200
     json = await response.json()
@@ -1356,7 +1354,7 @@ async def test_logbook_view_period_entity(hass, hass_client):
 
     # Test entries from tomorrow to 3 days ago with filter by entity_id
     response = await client.get(
-        "/api/logbook/{}?period=3&entity=switch.test".format(start_date.isoformat())
+        f"/api/logbook/{start_date.isoformat()}?period=3&entity=switch.test"
     )
     assert response.status == 200
     json = await response.json()
diff --git a/tests/components/mobile_app/test_entity.py b/tests/components/mobile_app/test_entity.py
index 27ce29ecd15..78259cd1145 100644
--- a/tests/components/mobile_app/test_entity.py
+++ b/tests/components/mobile_app/test_entity.py
@@ -11,7 +11,7 @@ _LOGGER = logging.getLogger(__name__)
 async def test_sensor(hass, create_registrations, webhook_client):
     """Test that sensors can be registered and updated."""
     webhook_id = create_registrations[1]["webhook_id"]
-    webhook_url = "/api/webhook/{}".format(webhook_id)
+    webhook_url = f"/api/webhook/{webhook_id}"
 
     reg_resp = await webhook_client.post(
         webhook_url,
@@ -74,7 +74,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
 async def test_sensor_must_register(hass, create_registrations, webhook_client):
     """Test that sensors must be registered before updating."""
     webhook_id = create_registrations[1]["webhook_id"]
-    webhook_url = "/api/webhook/{}".format(webhook_id)
+    webhook_url = f"/api/webhook/{webhook_id}"
     resp = await webhook_client.post(
         webhook_url,
         json={
@@ -93,7 +93,7 @@ async def test_sensor_must_register(hass, create_registrations, webhook_client):
 async def test_sensor_id_no_dupes(hass, create_registrations, webhook_client):
     """Test that sensors must have a unique ID."""
     webhook_id = create_registrations[1]["webhook_id"]
-    webhook_url = "/api/webhook/{}".format(webhook_id)
+    webhook_url = f"/api/webhook/{webhook_id}"
 
     payload = {
         "type": "register_sensor",
diff --git a/tests/components/mqtt_room/test_sensor.py b/tests/components/mqtt_room/test_sensor.py
index e8a9e62403f..b3155e563f4 100644
--- a/tests/components/mqtt_room/test_sensor.py
+++ b/tests/components/mqtt_room/test_sensor.py
@@ -16,10 +16,10 @@ NAME = "test_device"
 BEDROOM = "bedroom"
 LIVING_ROOM = "living_room"
 
-BEDROOM_TOPIC = "room_presence/{}".format(BEDROOM)
-LIVING_ROOM_TOPIC = "room_presence/{}".format(LIVING_ROOM)
+BEDROOM_TOPIC = f"room_presence/{BEDROOM}"
+LIVING_ROOM_TOPIC = f"room_presence/{LIVING_ROOM}"
 
-SENSOR_STATE = "sensor.{}".format(NAME)
+SENSOR_STATE = f"sensor.{NAME}"
 
 CONF_DEVICE_ID = "device_id"
 CONF_TIMEOUT = "timeout"
diff --git a/tests/components/openalpr_local/test_image_processing.py b/tests/components/openalpr_local/test_image_processing.py
index 291bed809c7..f28ee6f02d4 100644
--- a/tests/components/openalpr_local/test_image_processing.py
+++ b/tests/components/openalpr_local/test_image_processing.py
@@ -104,9 +104,7 @@ class TestOpenAlprLocal:
             setup_component(self.hass, ip.DOMAIN, config)
 
         state = self.hass.states.get("camera.demo_camera")
-        self.url = "{0}{1}".format(
-            self.hass.config.api.base_url, state.attributes.get(ATTR_ENTITY_PICTURE)
-        )
+        self.url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
 
         self.alpr_events = []
 
diff --git a/tests/components/ps4/test_media_player.py b/tests/components/ps4/test_media_player.py
index 56a659aa152..3bd75c40bed 100644
--- a/tests/components/ps4/test_media_player.py
+++ b/tests/components/ps4/test_media_player.py
@@ -156,7 +156,7 @@ async def mock_ddp_response(hass, mock_status_data, games=None):
 
     mock_code = mock_status_data.get("status_code")
     mock_status = mock_status_data.get("status")
-    mock_status_header = "{} {}".format(mock_code, mock_status)
+    mock_status_header = f"{mock_code} {mock_status}"
     mock_response = get_ddp_message(mock_status_header, mock_status_data).encode()
 
     if games is None:
@@ -179,7 +179,7 @@ async def test_media_player_is_setup_correctly_with_entry(hass):
 
     # Test that entity is added to hass.
     assert hass.data[PS4_DATA].protocol is not None
-    assert mock_entity_id == "media_player.{}".format(MOCK_NAME)
+    assert mock_entity_id == f"media_player.{MOCK_NAME}"
     assert mock_state == STATE_UNKNOWN
 
 
diff --git a/tests/components/python_script/test_init.py b/tests/components/python_script/test_init.py
index f61f0004723..d122fef0bd2 100644
--- a/tests/components/python_script/test_init.py
+++ b/tests/components/python_script/test_init.py
@@ -162,7 +162,7 @@ async def test_accessing_forbidden_methods(hass, caplog):
         caplog.records.clear()
         hass.async_add_job(execute, hass, "test.py", source, {})
         await hass.async_block_till_done()
-        assert "Not allowed to access {}".format(name) in caplog.text
+        assert f"Not allowed to access {name}" in caplog.text
 
 
 async def test_iterating(hass):
diff --git a/tests/components/recorder/test_init.py b/tests/components/recorder/test_init.py
index 8a56ba3d977..6b826d8c29b 100644
--- a/tests/components/recorder/test_init.py
+++ b/tests/components/recorder/test_init.py
@@ -109,7 +109,7 @@ def _add_entities(hass, entity_ids):
     """Add entities."""
     attributes = {"test_attr": 5, "test_attr_10": "nice"}
     for idx, entity_id in enumerate(entity_ids):
-        hass.states.set(entity_id, "state{}".format(idx), attributes)
+        hass.states.set(entity_id, f"state{idx}", attributes)
     wait_recording_done(hass)
 
     with session_scope(hass=hass) as session:
diff --git a/tests/components/roku/__init__.py b/tests/components/roku/__init__.py
index 638a37b193a..b46e57a38bd 100644
--- a/tests/components/roku/__init__.py
+++ b/tests/components/roku/__init__.py
@@ -24,7 +24,7 @@ class MockDeviceInfo(object):
 
     def __repr__(self):
         """Return the object representation of DeviceInfo."""
-        return "<DeviceInfo: %s-%s, SW v%s, Ser# %s (%s)>" % (
+        return "<DeviceInfo: {}-{}, SW v{}, Ser# {} ({})>".format(
             self.model_name,
             self.model_num,
             self.software_version,
diff --git a/tests/components/scene/test_init.py b/tests/components/scene/test_init.py
index 8211ff10857..fd09d378b46 100644
--- a/tests/components/scene/test_init.py
+++ b/tests/components/scene/test_init.py
@@ -87,11 +87,11 @@ class TestScene(unittest.TestCase):
             "scene:\n"
             "  - name: test\n"
             "    entities:\n"
-            "      {0}: on\n"
-            "      {1}:\n"
+            f"      {self.light_1.entity_id}: on\n"
+            f"      {self.light_2.entity_id}:\n"
             "        state: on\n"
             "        brightness: 100\n"
-        ).format(self.light_1.entity_id, self.light_2.entity_id)
+        )
 
         with io.StringIO(config) as file:
             doc = yaml_loader.yaml.safe_load(file)
diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py
index dbaa5e6e117..e4a4d4ca239 100644
--- a/tests/components/script/test_init.py
+++ b/tests/components/script/test_init.py
@@ -94,7 +94,7 @@ class TestScriptComponent(unittest.TestCase):
         ):
             assert not setup_component(
                 self.hass, "script", {"script": value}
-            ), "Script loaded with wrong config {}".format(value)
+            ), f"Script loaded with wrong config {value}"
 
             assert 0 == len(self.hass.states.entity_ids("script"))
 
diff --git a/tests/components/shell_command/test_init.py b/tests/components/shell_command/test_init.py
index 50c3c6bfb55..f046b5087f6 100644
--- a/tests/components/shell_command/test_init.py
+++ b/tests/components/shell_command/test_init.py
@@ -53,7 +53,7 @@ class TestShellCommand(unittest.TestCase):
             assert setup_component(
                 self.hass,
                 shell_command.DOMAIN,
-                {shell_command.DOMAIN: {"test_service": "date > {}".format(path)}},
+                {shell_command.DOMAIN: {"test_service": f"date > {path}"}},
             )
 
             self.hass.services.call("shell_command", "test_service", blocking=True)
@@ -137,7 +137,7 @@ class TestShellCommand(unittest.TestCase):
             assert setup_component(
                 self.hass,
                 shell_command.DOMAIN,
-                {shell_command.DOMAIN: {"test_service": "touch {}".format(path)}},
+                {shell_command.DOMAIN: {"test_service": f"touch {path}"}},
             )
 
             self.hass.services.call("shell_command", "test_service", blocking=True)
@@ -154,7 +154,7 @@ class TestShellCommand(unittest.TestCase):
         assert setup_component(
             self.hass,
             shell_command.DOMAIN,
-            {shell_command.DOMAIN: {"test_service": "echo {}".format(test_phrase)}},
+            {shell_command.DOMAIN: {"test_service": f"echo {test_phrase}"}},
         )
 
         self.hass.services.call("shell_command", "test_service", blocking=True)
@@ -170,7 +170,7 @@ class TestShellCommand(unittest.TestCase):
         assert setup_component(
             self.hass,
             shell_command.DOMAIN,
-            {shell_command.DOMAIN: {"test_service": ">&2 echo {}".format(test_phrase)}},
+            {shell_command.DOMAIN: {"test_service": f">&2 echo {test_phrase}"}},
         )
 
         self.hass.services.call("shell_command", "test_service", blocking=True)
diff --git a/tests/components/shopping_list/test_init.py b/tests/components/shopping_list/test_init.py
index bb65dcf631f..82b0d9b455d 100644
--- a/tests/components/shopping_list/test_init.py
+++ b/tests/components/shopping_list/test_init.py
@@ -99,7 +99,7 @@ async def test_deprecated_api_update(hass, hass_client, sl_setup):
 
     client = await hass_client()
     resp = await client.post(
-        "/api/shopping_list/item/{}".format(beer_id), json={"name": "soda"}
+        f"/api/shopping_list/item/{beer_id}", json={"name": "soda"}
     )
 
     assert resp.status == 200
@@ -107,7 +107,7 @@ async def test_deprecated_api_update(hass, hass_client, sl_setup):
     assert data == {"id": beer_id, "name": "soda", "complete": False}
 
     resp = await client.post(
-        "/api/shopping_list/item/{}".format(wine_id), json={"complete": True}
+        f"/api/shopping_list/item/{wine_id}", json={"complete": True}
     )
 
     assert resp.status == 200
@@ -174,9 +174,7 @@ async def test_api_update_fails(hass, hass_client, sl_setup):
     assert resp.status == 404
 
     beer_id = hass.data["shopping_list"].items[0]["id"]
-    resp = await client.post(
-        "/api/shopping_list/item/{}".format(beer_id), json={"name": 123}
-    )
+    resp = await client.post(f"/api/shopping_list/item/{beer_id}", json={"name": 123})
 
     assert resp.status == 400
 
@@ -221,7 +219,7 @@ async def test_deprecated_api_clear_completed(hass, hass_client, sl_setup):
 
     # Mark beer as completed
     resp = await client.post(
-        "/api/shopping_list/item/{}".format(beer_id), json={"complete": True}
+        f"/api/shopping_list/item/{beer_id}", json={"complete": True}
     )
     assert resp.status == 200
 
diff --git a/tests/components/sleepiq/test_init.py b/tests/components/sleepiq/test_init.py
index 67fe19da45a..6626be41a6b 100644
--- a/tests/components/sleepiq/test_init.py
+++ b/tests/components/sleepiq/test_init.py
@@ -18,13 +18,11 @@ def mock_responses(mock, single=False):
     else:
         suffix = ""
     mock.put(base_url + "login", text=load_fixture("sleepiq-login.json"))
-    mock.get(
-        base_url + "bed?_k=0987", text=load_fixture("sleepiq-bed{}.json".format(suffix))
-    )
+    mock.get(base_url + "bed?_k=0987", text=load_fixture(f"sleepiq-bed{suffix}.json"))
     mock.get(base_url + "sleeper?_k=0987", text=load_fixture("sleepiq-sleeper.json"))
     mock.get(
         base_url + "bed/familyStatus?_k=0987",
-        text=load_fixture("sleepiq-familystatus{}.json".format(suffix)),
+        text=load_fixture(f"sleepiq-familystatus{suffix}.json"),
     )
 
 
diff --git a/tests/components/switch/test_init.py b/tests/components/switch/test_init.py
index 9e34eb8f4ab..07ab1d19f55 100644
--- a/tests/components/switch/test_init.py
+++ b/tests/components/switch/test_init.py
@@ -77,7 +77,7 @@ class TestSwitch(unittest.TestCase):
             switch.DOMAIN,
             {
                 switch.DOMAIN: {CONF_PLATFORM: "test"},
-                "{} 2".format(switch.DOMAIN): {CONF_PLATFORM: "test2"},
+                f"{switch.DOMAIN} 2": {CONF_PLATFORM: "test2"},
             },
         )
 
diff --git a/tests/components/tplink/test_init.py b/tests/components/tplink/test_init.py
index 97512dfc9bd..d30a05ddbf8 100644
--- a/tests/components/tplink/test_init.py
+++ b/tests/components/tplink/test_init.py
@@ -73,7 +73,7 @@ async def test_configuring_device_types(hass, name, cls, platform, count):
         "homeassistant.components.tplink.common.SmartDevice._query_helper"
     ):
         discovery_data = {
-            "123.123.123.{}".format(c): cls("123.123.123.123") for c in range(count)
+            f"123.123.123.{c}": cls("123.123.123.123") for c in range(count)
         }
         discover.return_value = discovery_data
         await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}})
@@ -242,7 +242,7 @@ async def test_unload(hass, platform):
     with patch(
         "homeassistant.components.tplink.common.SmartDevice._query_helper"
     ), patch(
-        "homeassistant.components.tplink.{}.async_setup_entry".format(platform),
+        f"homeassistant.components.tplink.{platform}.async_setup_entry",
         return_value=mock_coro(True),
     ) as light_setup:
         config = {
diff --git a/tests/components/traccar/test_init.py b/tests/components/traccar/test_init.py
index 5a2dabcf6c2..a13a3d25a6c 100644
--- a/tests/components/traccar/test_init.py
+++ b/tests/components/traccar/test_init.py
@@ -75,7 +75,7 @@ async def webhook_id_fixture(hass, client):
 
 async def test_missing_data(hass, client, webhook_id):
     """Test missing data."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
     data = {"lat": "1.0", "lon": "1.1", "id": "123"}
 
     # No data
@@ -100,7 +100,7 @@ async def test_missing_data(hass, client, webhook_id):
 
 async def test_enter_and_exit(hass, client, webhook_id):
     """Test when there is a known zone."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
     data = {"lat": str(HOME_LATITUDE), "lon": str(HOME_LONGITUDE), "id": "123"}
 
     # Enter the Home
@@ -142,7 +142,7 @@ async def test_enter_and_exit(hass, client, webhook_id):
 
 async def test_enter_with_attrs(hass, client, webhook_id):
     """Test when additional attributes are present."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
     data = {
         "timestamp": 123456789,
         "lat": "1.0",
@@ -191,7 +191,7 @@ async def test_enter_with_attrs(hass, client, webhook_id):
 
 async def test_two_devices(hass, client, webhook_id):
     """Test updating two different devices."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
 
     data_device_1 = {"lat": "1.0", "lon": "1.1", "id": "device_1"}
 
@@ -223,7 +223,7 @@ async def test_two_devices(hass, client, webhook_id):
 )
 async def test_load_unload_entry(hass, client, webhook_id):
     """Test that the appropriate dispatch signals are added and removed."""
-    url = "/api/webhook/{}".format(webhook_id)
+    url = f"/api/webhook/{webhook_id}"
     data = {"lat": str(HOME_LATITUDE), "lon": str(HOME_LONGITUDE), "id": "123"}
 
     # Enter the Home
-- 
GitLab