Skip to content

Use non-autospec mock for Reolink's host tests #147619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged

Conversation

abmantis
Copy link
Member

Proposed change

Follow up to #146969

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @starkillerOG, mind taking a look at this pull request as it has been labeled with an integration (reolink) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of reolink can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign reolink Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
Contributor

@Copilot 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 switches Reolink host tests to use a non-autospec host mock (reolink_host) instead of reolink_connect and adds a missing renew AsyncMock in the test fixture.

  • Renamed fixture parameter and all references from reolink_connect to reolink_host
  • Updated method calls on the host mock to match the new fixture
  • Added host_mock.renew = AsyncMock() in conftest.py to support renewal tests

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/components/reolink/test_host.py Replaced reolink_connect references with reolink_host and adjusted mocks in tests
tests/components/reolink/conftest.py Initialized renew as an AsyncMock on the host mock

Comment on lines 58 to 61
reolink_host.baichuan.events_active = False
reolink_host.baichuan.subscribe_events.side_effect = ReolinkError("Test error")


Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

[nitpick] These lines at the end of test_setup_with_tcp_push set events_active and a side effect on subscribe_events, but the test does not trigger another subscription call afterward. Consider removing these redundant assignments to keep the test focused.

Suggested change
reolink_host.baichuan.events_active = False
reolink_host.baichuan.subscribe_events.side_effect = ReolinkError("Test error")

Copilot uses AI. Check for mistakes.

Comment on lines 81 to 84
reolink_host.baichuan.events_active = False
reolink_host.baichuan.subscribe_events.side_effect = ReolinkError("Test error")


Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

[nitpick] In test_unloading_with_tcp_push, these lines set events_active and a side effect on subscribe_events after unloading, but no further behavior is asserted. You can remove these unused lines to reduce noise in the test.

Suggested change
reolink_host.baichuan.events_active = False
reolink_host.baichuan.subscribe_events.side_effect = ReolinkError("Test error")

Copilot uses AI. Check for mistakes.

Comment on lines 252 to 254
reolink_host.subscribed.return_value = True


Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

[nitpick] This assignment in the test_ONVIF_not_supported test is not used after the test assertion. It can be removed to clean up the test setup.

Suggested change
reolink_host.subscribed.return_value = True

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@starkillerOG starkillerOG left a comment

Choose a reason for hiding this comment

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

LGTM, thank you very much!

@starkillerOG starkillerOG merged commit 06d04c0 into dev Jun 26, 2025
34 checks passed
@starkillerOG starkillerOG deleted the reolink_test_host_nospec branch June 26, 2025 18:55
@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants