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 <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Jan Bouwhuis 2022-08-25 12:29:31 +02:00 committed by GitHub
parent ad6beac535
commit 7fc294d9b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -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)

View file

@ -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