Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tests/components/trace/test_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,24 @@ def next_id():
await hass.async_block_till_done()

# List traces
await client.send_json({"id": next_id(), "type": "trace/list"})
await client.send_json({"id": next_id(), "type": "trace/list", "domain": "script"})
response = await client.receive_json()
assert response["success"]
assert len(response["result"]) == 2
assert len(_find_traces(response["result"], domain, "sun")) == 1
if domain == "automation":
assert len(response["result"]) == 1
else:
assert len(response["result"]) == 2
assert len(_find_traces(response["result"], "script", "moon")) == 1
sun_run_id = _find_run_id(response["result"], domain, "sun")
moon_run_id = _find_run_id(response["result"], "script", "moon")
if domain == "automation":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using if/else logic in the tests together with parameters is not the best way to do test parametrization. Logic in tests is bad for both readability and robustness.

If it's not possible to parametrize and avoid the logic it's probably better to have separate tests for the different cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll refactor to pass as parameters instead in a follow-up.

await client.send_json(
{"id": next_id(), "type": "trace/list", "domain": "automation"}
)
response = await client.receive_json()
assert response["success"]
assert len(response["result"]) == 1
assert len(_find_traces(response["result"], domain, "sun")) == 1
sun_run_id = _find_run_id(response["result"], domain, "sun")
assert sun_run_id != moon_run_id

# Get trace
Expand Down
6 changes: 6 additions & 0 deletions tests/helpers/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def assert_element(trace_element, expected_element, path):
assert trace_element._error is None


@pytest.fixture(autouse=True)
def prepare_condition_trace():
"""Clear previous trace."""
trace.trace_clear()


def assert_condition_trace(expected):
"""Assert a trace condition sequence is as expected."""
condition_trace = trace.trace_get(clear=False)
Expand Down