From 7fc294d9b172a3e16fd2c7871c9c5c844c46207c Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Thu, 25 Aug 2022 12:29:31 +0200 Subject: [PATCH] Set cv hass in hass fixture (#77271) * Set cv hass in hass fixture * Move test_hass_cv and update docstring * Update tests/test_test_fixtures.py Co-authored-by: Martin Hjelmare Co-authored-by: Martin Hjelmare --- tests/conftest.py | 2 ++ tests/test_test_fixtures.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 889568127cb..4a02083610b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -329,6 +329,8 @@ def hass(loop, load_registries, hass_storage, request): exceptions = [] hass = loop.run_until_complete(async_test_home_assistant(loop, load_registries)) + ha._cv_hass.set(hass) + orig_exception_handler = loop.get_exception_handler() loop.set_exception_handler(exc_handle) diff --git a/tests/test_test_fixtures.py b/tests/test_test_fixtures.py index 90362e95819..376cd79488f 100644 --- a/tests/test_test_fixtures.py +++ b/tests/test_test_fixtures.py @@ -4,6 +4,8 @@ import socket import pytest import pytest_socket +from homeassistant.core import async_get_hass + def test_sockets_disabled(): """Test we can't open sockets.""" @@ -16,3 +18,12 @@ def test_sockets_enabled(socket_enabled): mysocket = socket.socket() with pytest.raises(pytest_socket.SocketConnectBlockedError): mysocket.connect(("127.0.0.2", 1234)) + + +async def test_hass_cv(hass): + """Test hass context variable. + + When tests are using the `hass`, this tests that the hass context variable was set + in the fixture and that async_get_hass() works correctly. + """ + assert async_get_hass() is hass