Keep tests from changing logger levels and fixture data for later tests (#1844)
Some checks failed
CI / Perform Lint Checks (3.15) (push) Has been cancelled
CodeQL Checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.14 on macos-latest (push) Has been cancelled
CI / Python 3.15 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.14 on ubuntu-latest (push) Has been cancelled
CI / Python 3.15 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CI / Python 3.14 on windows-latest (push) Has been cancelled
CI / Python 3.15 on windows-latest (push) Has been cancelled
Stale / stale (push) Has been cancelled

Some tests leave the `kasa` logger at a different level or rename devices
in shared fixture data. Later log assertions and device dump comparisons
then pass or fail depending on the test order.

This PR restores logger levels through `caplog` and renames devices on
copies, so the affected tests pass independently of their order.

In details:
- Use `caplog.set_level` for tests that change the `kasa` logger, and
  remove an unused logger override.
- Add an autouse fixture that restores any changed logger levels and
  fails the test with a pointer to `caplog.set_level`.
- Rename README devices on deep copies of the fixture data.
- Cover KLAP handshake debug logging explicitly, instead of relying on
  an earlier test leaving DEBUG enabled.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZeliardM
2026-11-18 08:14:51 -05:00
committed by GitHub
parent e823e332ef
commit 3bf95247d4
5 changed files with 71 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import asyncio
import copy
import pytest
import xdoctest
@@ -181,6 +182,11 @@ async def readmes_mock(mocker: MockerFixture):
"127.0.0.5": get_fixture_info("HS220(US)_1.0_1.5.7.json", "IOT"), # Dimmer
"127.0.0.6": get_fixture_info("H200(US)_1.0_1.3.6.json", "SMARTCAM"), # Hub
}
# Rename the devices on copies, not on the fixtures other tests share
fixture_infos = {
ip: info._replace(data=copy.deepcopy(info.data))
for ip, info in fixture_infos.items()
}
fixture_infos["127.0.0.1"].data["system"]["get_sysinfo"]["alias"] = (
"Bedroom Power Strip"
)