I'm writing tests for a Home Assistant integration using tests from another integration as an example. There is a method that is called from each test function that is some how calling patch
with two positional arguments:
async def setup_platform(hass, platform):
"""Set up the ring platform and prerequisites."""
MockConfigEntry(domain=DOMAIN, data={"username": "foo", "token": {}}).add_to_hass(
hass
)
with patch("homeassistant.components.ring.PLATFORMS", [platform]):
assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
The first positional argument "homeassistant.components.ring.PLATFORMS"
is obviously a string but is pointing to the constant PLATFORMS
which is a tuple ("binary_sensor", "light", "sensor", "switch", "camera")
. The second positional argument platform
is passed in setup_platform
as a string that will be either "binary_sensor"
, "light"
, "sensor"
, "switch"
or "camera"
(same items as the PLATFORMS
tuple), but gets passed into patch
as a dictionary with one string item.
My understanding of what's happening is this results in only the platform
passed being patched.
What I can't figure out is how two positional arguments can be passed into patch
when it only accepts one positional argument. Are the two positional arguments some how being combined into one before patch
is called?