Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pytest to 7.4.1 #96995

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pytest-timeout==2.1.0
pytest-unordered==0.5.2
pytest-picked==0.4.6
pytest-xdist==3.3.1
pytest==7.3.1
pytest==7.4.1
requests_mock==1.11.0
respx==0.20.2
syrupy==4.2.1
Expand Down
45 changes: 30 additions & 15 deletions tests/components/mqtt/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3805,10 +3805,12 @@ def _check_entities() -> int:
async_fire_mqtt_message(hass, "test-topic_manual1", "manual1_intial")
async_fire_mqtt_message(hass, "test-topic_manual3", "manual3_intial")

assert (state := hass.states.get("sensor.test_manual1")) is not None
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, why is this changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is an open bug in pytest assertion rewriter. See pytest-dev/pytest#11239

Tbh I'm not sure if we should update. The intention behind 8579d5f was more to see if CI would pass (it should 🤞🏻). 7.4.0 fixed a lot of deprecation warnings which would appear in Python 3.12. What do you think, should we update now even if := in asserts don't work?

Copy link
Member

Choose a reason for hiding this comment

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

Are these the only places where assertions are used using the walrus? I don't think they're that many tbh

Without the walrus the test is better to read imo

Copy link
Member Author

Choose a reason for hiding this comment

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

Are these the only places where assertions are used using the walrus? I don't think they're that many tbh

AFAIC yes. At least those two files are the only ones with errors during the last CI run.
https://github.com/home-assistant/core/actions/runs/6060843262

What's difficult IMO is that the test case using := is normally fine. It's actually an unrelated test case in the same test file that breaks which just happens to use the same name (state in this case) in an assert. This should really be fixed in pytest.

Without the walrus the test is better to read imo

It depends. I'm probably +0 on this. Somethings can I see the appeal of using assignment expressions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened a PR upstream to fix it: pytest-dev/pytest#11414

state = hass.states.get("sensor.test_manual1")
assert state is not None
assert state.attributes["friendly_name"] == "test_manual1"
assert state.state == "manual1_intial"
assert (state := hass.states.get("sensor.test_manual3")) is not None
state = hass.states.get("sensor.test_manual3")
assert state is not None
assert state.attributes["friendly_name"] == "test_manual3"
assert state.state == "manual3_intial"
assert _check_entities() == 3
Expand Down Expand Up @@ -3839,16 +3841,20 @@ def _check_entities() -> int:
assert entry.state is ConfigEntryState.LOADED
await hass.async_block_till_done()

assert (state := hass.states.get("sensor.test_manual1")) is not None
state = hass.states.get("sensor.test_manual1")
assert state is not None
assert state.attributes["friendly_name"] == "test_manual1_updated"
assert state.state == STATE_UNKNOWN
assert (state := hass.states.get("sensor.test_manual2_new")) is not None
state = hass.states.get("sensor.test_manual2_new")
assert state is not None
assert state.attributes["friendly_name"] == "test_manual2_new"
assert state.state is STATE_UNKNOWN
# State of test_manual3 is still loaded but is unavailable
assert (state := hass.states.get("sensor.test_manual3")) is not None
state = hass.states.get("sensor.test_manual3")
assert state is not None
assert state.state is STATE_UNAVAILABLE
assert (state := hass.states.get("sensor.test_discovery")) is not None
state = hass.states.get("sensor.test_discovery")
assert state is not None
assert state.state is STATE_UNAVAILABLE
# The entity is not loaded anymore
assert _check_entities() == 2
Expand All @@ -3857,11 +3863,14 @@ def _check_entities() -> int:
async_fire_mqtt_message(hass, "test-topic_manual2", "manual2_update")
async_fire_mqtt_message(hass, "test-topic_manual3", "manual3_update")

assert (state := hass.states.get("sensor.test_manual1")) is not None
state = hass.states.get("sensor.test_manual1")
assert state is not None
assert state.state == "manual1_update"
assert (state := hass.states.get("sensor.test_manual2_new")) is not None
state = hass.states.get("sensor.test_manual2_new")
assert state is not None
assert state.state == "manual2_update"
assert (state := hass.states.get("sensor.test_manual3")) is not None
state = hass.states.get("sensor.test_manual3")
assert state is not None
assert state.state is STATE_UNAVAILABLE

# Reload manual configured items and assert again
Expand All @@ -3876,13 +3885,16 @@ def _check_entities() -> int:
)
await hass.async_block_till_done()

assert (state := hass.states.get("sensor.test_manual1")) is not None
state = hass.states.get("sensor.test_manual1")
assert state is not None
assert state.attributes["friendly_name"] == "test_manual1_updated"
assert state.state == STATE_UNKNOWN
assert (state := hass.states.get("sensor.test_manual2_new")) is not None
state = hass.states.get("sensor.test_manual2_new")
assert state is not None
assert state.attributes["friendly_name"] == "test_manual2_new"
assert state.state == STATE_UNKNOWN
assert (state := hass.states.get("sensor.test_manual3")) is not None
state = hass.states.get("sensor.test_manual3")
assert state is not None
assert state.state == STATE_UNAVAILABLE
assert _check_entities() == 2

Expand All @@ -3892,9 +3904,12 @@ def _check_entities() -> int:
async_fire_mqtt_message(hass, "test-topic_manual2", "manual2_update_after_reload")
async_fire_mqtt_message(hass, "test-topic_manual3", "manual3_update_after_reload")

assert (state := hass.states.get("sensor.test_manual1")) is not None
state = hass.states.get("sensor.test_manual1")
assert state is not None
assert state.state == "manual1_update_after_reload"
assert (state := hass.states.get("sensor.test_manual2_new")) is not None
state = hass.states.get("sensor.test_manual2_new")
assert state is not None
assert state.state == "manual2_update_after_reload"
assert (state := hass.states.get("sensor.test_manual3")) is not None
state = hass.states.get("sensor.test_manual3")
assert state is not None
assert state.state is STATE_UNAVAILABLE
3 changes: 2 additions & 1 deletion tests/helpers/test_entity_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,8 @@ def test_migrate_entity_to_new_platform(

assert not entity_registry.async_get_entity_id("light", "hue", orig_unique_id)

assert (new_entry := entity_registry.async_get("light.light")) is not orig_entry
new_entry = entity_registry.async_get("light.light")
assert new_entry is not orig_entry

assert new_entry.config_entry_id == new_config_entry.entry_id
assert new_entry.unique_id == new_unique_id
Expand Down