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