Skip to content

Commit

Permalink
Show diff when API calls have changed (#3646)
Browse files Browse the repository at this point in the history
* Show diff when API calls have changed

* Format code

---------

Co-authored-by: Joakim Sørensen <[email protected]>
  • Loading branch information
emontnemery and ludeeus authored Apr 18, 2024
1 parent 47a49e4 commit 6242b71
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Any, Generator
from unittest.mock import MagicMock, patch

from _pytest.assertion.util import _compare_eq_iterable
from awesomeversion import AwesomeVersion
import freezegun
from homeassistant import loader
Expand Down Expand Up @@ -418,4 +419,20 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
with open("tests/output/proxy_calls.json", encoding="utf-8") as file:
current = json.load(file)
if current != filtered_calls:
raise AssertionError("API calls have changed, run scripts/snapshot-update")
diff = ""
for test in current:
if test not in filtered_calls:
diff += f"Test '{test}' was removed\n"
for test in filtered_calls:
if test not in current:
diff += f"Test '{test}' was added\n"
for test in filtered_calls:
if test not in current:
continue
if filtered_calls[test] == current[test]:
continue
diff += f"Test '{test}' has changed\n"
diff += "\n".join(_compare_eq_iterable(filtered_calls[test], current[test], 3))
diff += "\n"

raise AssertionError(f"API calls have changed, run scripts/snapshot-update\n{diff}")

0 comments on commit 6242b71

Please sign in to comment.