tests: add type annotations to CLI, protocol, and smartcam tests#1687
Open
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
Open
tests: add type annotations to CLI, protocol, and smartcam tests#1687ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1687 +/- ##
=======================================
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR improves static typing coverage in the test suite by adding explicit type annotations to tests under tests/cli/, tests/protocols/, and tests/smartcam/, aligning the tests with the repository’s broader type-checking practices (e.g., mypy in pre-commit).
Changes:
- Added explicit
-> Nonereturn annotations to async and sync test functions across the targeted test files. - Added parameter type annotations for common pytest fixtures and parametrized inputs (e.g.,
Device,CliRunner,MockerFixture,pytest.LogCaptureFixture, unions likestr | None). - Introduced a small number of targeted
# type: ignore[...]annotations in protocol tests where runtime behavior intentionally diverges from static typing.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tests/cli/test_hub.py |
Types dev, runner, caplog, and mocker in hub CLI tests; adds -> None. |
tests/cli/test_vacuum.py |
Types dev, runner, and mocker in vacuum CLI tests; adds -> None. |
tests/protocols/test_iotprotocol.py |
Adds from __future__ import annotations, fixture/input typing, and targeted type: ignore for known runtime-only behavior. |
tests/protocols/test_smartprotocol.py |
Adds fixture/input typing (including parametrized ints/enums) and -> None across smart protocol tests. |
tests/smartcam/modules/test_alarm.py |
Adds -> None return typing for alarm module tests. |
tests/smartcam/modules/test_battery.py |
Types parametrized inputs with appropriate unions (e.g., `str |
tests/smartcam/modules/test_camera.py |
Adds -> None return typing for camera module tests. |
tests/smartcam/modules/test_childsetup.py |
Adds fixture parameter types (MockerFixture, LogCaptureFixture) and -> None. |
tests/smartcam/modules/test_detections.py |
Adds typing to selected helper parameters and -> None to the async test function. |
tests/smartcam/modules/test_pantilt.py |
Adds fixture parameter types and -> None across PanTilt module tests. |
tests/smartcam/test_smartcamdevice.py |
Adds -> None and fixture parameter typing (including FrozenDateTimeFactory) for smartcam device tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add type annotations (
-> Nonereturn types and parameter types) to test files in thetests/cli/,tests/protocols/, andtests/smartcam/directories. This enables mypy to check test function bodies, catching type errors that were previously hidden.Changes
Return types:
-> Noneto all test functions across 11 filesParameter types:
dev: Device,runner: CliRunner,caplog: pytest.LogCaptureFixture,mocker: MockerFixturemocker: MockerFixture,transport_class: type[XorTransport]/type[BaseTransport],protocol_class: type[BaseProtocol](where type-safe),caplog: pytest.LogCaptureFixture,log_level: int,retry_count: intdummy_protocol: SmartProtocol,mocker: MockerFixture,batch_size: int,error_code: SmartErrorCode/int,list_sum: int,request_size: intraw: str | None,expected: float | None,protocol_filter: set[str] | None,fixture_name: strMypy fixes:
# type: ignore[misc]for intentional__init__introspection in signature tests# type: ignore[attr-defined]for runtime-only deprecatedTPLinkSmartHomeProtocolimportmock_response: dictto fix indexing error from heterogeneous dict literalencryption_class/encrypt_class/decrypt_classand someprotocol_classparams untyped (duck-typed parametrized values with no common interface)Files changed (11)
tests/cli/test_hub.py,tests/cli/test_vacuum.py,tests/protocols/test_iotprotocol.py,tests/protocols/test_smartprotocol.py,tests/smartcam/modules/test_alarm.py,tests/smartcam/modules/test_battery.py,tests/smartcam/modules/test_camera.py,tests/smartcam/modules/test_childsetup.py,tests/smartcam/modules/test_detections.py,tests/smartcam/modules/test_pantilt.py,tests/smartcam/test_smartcamdevice.pyMerge order
This is PR 8 of 9 in the test modernization series. No file overlaps with other PRs.
Verification