From 3c508084651845f0ab6af54851be8da46c3017ce Mon Sep 17 00:00:00 2001 From: fstwn Date: Thu, 29 Oct 2026 12:05:40 +0100 Subject: [PATCH] test: restore app.state by hand in the token lifetime test Since pytest 9.2.0, monkeypatch.setattr restores only what was in the instance __dict__; Starlette's State keeps its values in _state, so the undo deleted gh_token_minutes and the next test on the same worker failed in CI. --- tests/api/test_gh_token_lifetime.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/api/test_gh_token_lifetime.py b/tests/api/test_gh_token_lifetime.py index 2df3bb66..2ae397e3 100644 --- a/tests/api/test_gh_token_lifetime.py +++ b/tests/api/test_gh_token_lifetime.py @@ -65,10 +65,16 @@ def test_a_malformed_header_lives_thirty_minutes(api, account, header): assert lifetime(sign_in(api, account, header)) == 30 * 60 -def test_the_setting_is_respected(api, account, monkeypatch): - monkeypatch.setattr(api.app.state, 'gh_token_minutes', 2 * 60) - assert lifetime(sign_in(api, account, GH)) == 2 * 3600 - assert lifetime(sign_in(api, account, 'web/0.6.2.1')) == 30 * 60 +def test_the_setting_is_respected(api, account): + # not monkeypatch.setattr: since pytest 9.2 its undo deletes an attribute + # that is not in the instance __dict__, and State keeps its own + kept = api.app.state.gh_token_minutes + api.app.state.gh_token_minutes = 2 * 60 + try: + assert lifetime(sign_in(api, account, GH)) == 2 * 3600 + assert lifetime(sign_in(api, account, 'web/0.6.2.1')) == 30 * 60 + finally: + api.app.state.gh_token_minutes = kept def test_the_long_token_is_a_working_token(api, account):