Verify respx mock routes are cleaned up when tests finish (#122852)

This commit is contained in:
Erik Montnemery 2024-07-30 17:12:58 +02:00 committed by GitHub
parent 4a34855a92
commit 6840f27bc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,6 +34,7 @@ import multidict
import pytest
import pytest_socket
import requests_mock
import respx
from syrupy.assertion import SnapshotAssertion
from homeassistant import block_async_io
@ -398,6 +399,13 @@ def verify_cleanup(
# Restore the default time zone to not break subsequent tests
dt_util.DEFAULT_TIME_ZONE = datetime.UTC
try:
# Verify respx.mock has been cleaned up
assert not respx.mock.routes, "respx.mock routes not cleaned up, maybe the test needs to be decorated with @respx.mock"
finally:
# Clear mock routes not break subsequent tests
respx.mock.clear()
@pytest.fixture(autouse=True)
def reset_hass_threading_local_object() -> Generator[None]: