Speed up tests by making mock_get_source_ip session scoped (#117096)

This commit is contained in:
J. Nick Koston 2024-05-08 16:42:35 -05:00 committed by GitHub
parent 03dcede211
commit 6eeeafa8b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

View File

@ -4,10 +4,13 @@ import pytest
@pytest.fixture(autouse=True)
def mock_get_source_ip():
"""Override mock of network util's async_get_source_ip."""
def mock_network():
"""Override mock of network util's async_get_adapters."""
@pytest.fixture(autouse=True)
def mock_network():
"""Override mock of network util's async_get_adapters."""
def override_mock_get_source_ip(mock_get_source_ip):
"""Override mock of network util's async_get_source_ip."""
mock_get_source_ip.stop()
yield
mock_get_source_ip.start()

View File

@ -1145,14 +1145,18 @@ def mock_network() -> Generator[None, None, None]:
yield
@pytest.fixture(autouse=True)
def mock_get_source_ip() -> Generator[None, None, None]:
@pytest.fixture(autouse=True, scope="session")
def mock_get_source_ip() -> Generator[patch, None, None]:
"""Mock network util's async_get_source_ip."""
with patch(
patcher = patch(
"homeassistant.components.network.util.async_get_source_ip",
return_value="10.10.10.10",
):
yield
)
patcher.start()
try:
yield patcher
finally:
patcher.stop()
@pytest.fixture