Skip to content

tests: fix typos, child device subtype, CLI patch path, and deprecation test logic#1677

Open
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
ZeliardM:feature/test-clean-up
Open

tests: fix typos, child device subtype, CLI patch path, and deprecation test logic#1677
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
ZeliardM:feature/test-clean-up

Conversation

@ZeliardM
Copy link
Copy Markdown
Contributor

@ZeliardM ZeliardM commented Mar 21, 2026

Summary

Small correctness fixes across tests and source code — foundation cleanup before type annotation PRs.

Changes

  • CHANGELOG.md: Fix typo valid_temperate_rangevalid_temperature_range
  • kasa/smart/smartchilddevice.py: Add DeviceType.WallSwitch to sub-bulb child type mapping (plug.powerstrip.sub-bulb)
  • tests/test_cli.py: Fix redact_data patch path to match actual module location
  • tests/test_device.py: Fix deprecation test logic — add deprecated_warns_before_attribute_error set to properly handle attributes that emit DeprecationWarning even when the module isn't present, and fix _test_attribute condition to correctly combine is_expected and will_raise
  • tests/test_discovery.py: Replace deprecated supported_modules with modules in discovery test
  • pyproject.toml: Fix dead mypy override — kasa.tests.*tests.* (tests live at tests/, not kasa/tests/, so annotation-unchecked suppression was never applied)

Merge order

This is PR 1 of 9 in the test modernization series. Merge before all other PRs in the series.

Order PR Scope
1 #1677 Test and source cleanup
2 #1681 CI: pin GitHub Actions to SHA
3 #1682 Docs: modernize docstrings
4 #1683 Tests: centralize session cleanup
5 #1684 Tests: transport type annotations
6 #1685 Tests: IoT type annotations
7 #1686 Tests: Smart type annotations
8 #1687 Tests: CLI/protocols/smartcam type annotations
9 #1688 Tests: top-level type annotations

Verification

  • All pre-commit hooks pass (ruff, ruff-format, mypy)
  • Full test suite passes after sequential merge of all 9 PRs (10,656 passed, 194 skipped)

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (76d9f68) to head (d9a9721).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1677   +/-   ##
=======================================
  Coverage   93.22%   93.22%           
=======================================
  Files         157      157           
  Lines        9815     9815           
  Branches     1003     1003           
=======================================
  Hits         9150     9150           
  Misses        472      472           
  Partials      193      193           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZeliardM
Copy link
Copy Markdown
Contributor Author

@rytilahti This PR cleans up a lot of CI testing warnings and errors, the only thing left now is the handling of the fixture files and incomplete fixture file data warning, which I figured was still useful. Let me know if you have any questions.

Copilot AI review requested due to automatic review settings April 5, 2026 19:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates documentation/examples and strengthens test hygiene by ensuring transport/client resources are reliably cleaned up during pytest runs, while also tightening deprecation and discovery CLI test behavior.

Changes:

  • Add automatic teardown in multiple transport tests to close created transports and their underlying aiohttp sessions.
  • Modernize IotBulb doctest examples to use module-based light APIs and align the doctest fixture setup accordingly.
  • Small correctness/maintenance updates: deprecation-warning expectations, discovery/CLI redaction patch point, child subtype mapping, and GitHub Actions tweaks.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/transports/test_sslaestransport.py Autouse fixture tracks and closes created SslAesTransport instances after tests.
tests/transports/test_linkietransport.py Autouse fixture tracks and closes LinkieTransportV2 to avoid unclosed HttpClient sessions.
tests/transports/test_klaptransport.py Autouse fixture closes created transports; adds explicit protocol.close() in query test; removes manual session injection.
tests/transports/test_aestransport.py Autouse fixture tracks/closes AesTransport instances to prevent session leaks.
tests/test_readme_examples.py Prepares bulb fixture state (alias + update) so updated iotbulb doctests match expected output.
tests/test_httpclient.py Ensures HttpClient is closed via finally in error-path test.
tests/test_discovery.py Updates assertions to reflect HttpClient internal session behavior and ensures devices/sessions are disconnected/closed.
tests/test_deviceconfig.py Closes aiohttp.ClientSession used in config serialization tests via finally.
tests/test_device.py Refines deprecation-warning expectations for deprecated attributes that warn before raising AttributeError.
tests/test_cli.py Patches redaction at the CLI import site for discover raw testing.
kasa/smart/smartchilddevice.py Adds plug.powerstrip.sub-bulb subtype mapping to DeviceType.Bulb.
kasa/iot/iotbulb.py Updates docstring examples and fixes a minor wording typo (“fetch updated values”).
CHANGELOG.md Fixes typo in deprecated attribute name (valid_temperature_range).
.github/workflows/codeql-analysis.yml Enables CodeQL action file coverage on PRs via env var.
.github/actions/setup/action.yaml Updates pre-commit cache action to actions/cache@v5.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

The typo fixes and other maintenance work looks good to me, but to me the try-final pattern looks like it complicates the existing code without much benefits?

@ZeliardM
Copy link
Copy Markdown
Contributor Author

ZeliardM commented Apr 5, 2026

@rytilahti I'm going to take the comments and see if I can clean the handling up.

I agree with the actions piece, we leave it as for now and do another PR later to resolve for all actions.

I also agree on the strict typing. I also feel like there needs to be a much larger and broader inspection of tests as a whole, make sure that we are getting the coverages we need for everything and handling everything correctly. Not sure if you want to leave it as is for now and clean up all tests, typing and coverages, in another larger PR.

I will look and see if there is a better handling process for the client so that the tests are not having to be patched like this to make sure the client is closed properly.

@rytilahti
Copy link
Copy Markdown
Member

rytilahti commented Apr 6, 2026

This PR currently does many different things, so splitting it up would make sense to me. Things like fixing the missing type hints can be done in a single PR, fixing the docstrings in another, etc. This way we can merge the easy ones (CI maintenance, documentation fixes) immediately, and still keep the git history sane (the PR title is used in the git log, so the current one is very non-descriptive and reads like some change log entries "fixed some bugs"..).

@ZeliardM
Copy link
Copy Markdown
Contributor Author

ZeliardM commented Apr 6, 2026

@rytilahti Gotcha. I can break this up into a couple of smaller PRs and make them cleaner along the way. Will do!

@ZeliardM ZeliardM force-pushed the feature/test-clean-up branch from ee464a4 to e2f78d0 Compare April 6, 2026 16:28
@ZeliardM ZeliardM changed the title Clean-up tests, latent code issues, and typos Fix typos, child device subtype, CLI test patch path, and deprecation test logic Apr 6, 2026
@ZeliardM
Copy link
Copy Markdown
Contributor Author

ZeliardM commented Apr 6, 2026

@rytilahti Ok, this PR has been updated to just handle the smaller pieces.

… test logic

- Fix CHANGELOG typo: valid_temperate_range -> valid_temperature_range
- Add plug.powerstrip.sub-bulb child device type mapping
- Narrow discover raw test to patch CLI-level redact path
- Fix deprecated attribute test logic for attrs that warn before raising
- Update supported_modules -> modules in discovery test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants