mirror of
https://github.com/ansible/awx.git
synced 2026-10-29 22:03:20 -02:30
Use monkeypatch.setitem for awxkit config in tests awxkit's `config` is a PseudoNamespace, a dict subclass that exposes its keys as attributes. pytest 9.2.0 changed monkeypatch.setattr to read the previous value from the target's __dict__ instead of via getattr, so for a dict-backed namespace it always records the attribute as "did not exist" and schedules a delattr on undo. Patching the same key twice (autouse fixture plus test body) then deletes it twice, and PseudoNamespace.__delattr__ raises KeyError at teardown. This breaks 13 tests in test/cli/test_authentication.py on pytest >= 9.2.0. monkeypatch.setitem records the old value with dict.get, which sees the dict-backed storage correctly, so undo restores or removes exactly what was there on any pytest version. test/api/pages/test_base.py is updated for the same reason: under 9.2.0 its undo would delete a pre-existing base_url or credentials value instead of restoring it. Claude-Session: https://claude.ai/code/session_01SbeYPdRRLaGCk74gJHq9yS Signed-off-by: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
22 lines
534 B
Python
22 lines
534 B
Python
from http.client import NOT_FOUND
|
|
import pytest
|
|
|
|
from awxkit.config import config
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def setup_config(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setitem(config, "credentials", {"default": {"username": "foo", "password": "bar"}})
|
|
monkeypatch.setitem(config, "base_url", "")
|
|
|
|
|
|
@pytest.fixture
|
|
def response(mocker):
|
|
r = mocker.Mock()
|
|
r.status_code = NOT_FOUND
|
|
r.json.return_value = {
|
|
"token": "my_personal_token",
|
|
"access_token": "my_token",
|
|
}
|
|
return r
|