fix: do not monkeypatch attributes on Starlette State in tests

pytest 9.2 reads the old value of a monkeypatched attribute from the
instance __dict__. Starlette State keeps attributes in an internal
dict, so the old value looks unset and the teardown deletes the
attribute for the rest of the test session. The first test that
touches app.state.exiting passes but removes it, and every later
monkeypatch.setattr on it fails with AttributeError.

Use plain assignments instead.
This commit is contained in:
YueGuobin committed 2026-11-04 09:22:15 +08:00
1 parent 8f763c0439
commit a56fce4c36
3 files changed
+50 -29

No files matched your search

+4 -1
View File
@@ -640,7 +640,10 @@ async def test_connect_notification_poison_frame_autoreconnects(compute, monkeyp
# would execute module-level from-imports while the autouse fixture's
# monkeypatches are active, freezing patched objects into namespaces)
monkeypatch.delattr(sys, "_called_from_test", raising=False)
monkeypatch.setattr(gns3_app.state, "exiting", False)
# plain assignment instead of monkeypatch.setattr: Starlette's State keeps
# attributes in an internal dict, so pytest 9.2+ teardown would delete the
# attribute for the rest of the test session
gns3_app.state.exiting = False
async def fake_connect():
compute._reconnect_attempted = True