Refactor integration tests to use stateful fakes and fixtures#868
Open
allenporter wants to merge 1 commit into
Open
Refactor integration tests to use stateful fakes and fixtures#868allenporter wants to merge 1 commit into
allenporter wants to merge 1 commit into
Conversation
e5387b2 to
0f60d33
Compare
0f60d33 to
6ad41f2
Compare
6ad41f2 to
bdb8b88
Compare
bdb8b88 to
c90b396
Compare
Lash-L
approved these changes
Jul 8, 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.
Motivation
Following the merge of the
roborock.testinglibrary (#860), this PR refactors integration tests intest_device_manager.pyto useFakeRoborockCloudandV1VacuumSimulator. In doing so, we introduce some usability improvements toroborock.testingto simplify test implementation for both internal and downstream consumers (like the Home Assistant integration):patch_device_managerto be exposed as a standard pytest fixture. This removes the need for deepwith cloud.patch_device_manager():indentation, especially when asserting reconnection backoffs in background tasks which must run across the entire lifespan of the test.inject_error(exception)andclear_error()API toFakeChannel. Test writers can now easily simulate and recover from connection/subscription/publish failures without hacky manual modification of mockside_effectattributes and private wrappers.set_homes_response()onFakeWebApiClientto accept theHomeDatadataclass directly (serializing it automatically under the hood). Added aget_default_home_data()helper so tests can retrieve the default registered layout and copy/modify it using standarddataclasses.replacerather than building raw dictionaries from scratch.publish_handlerregistration property onFakeChannelinstead of overriding mock attributes directly, keeping the mock assertions clean and orthogonal.patch_device_manager()'s context manager. Downstream integration test suites run instantly out-of-box without needing duplicate sleep-patching fixtures.Changes Made
roborock.testing:channel.py: Addedpublish_handler,inject_error(exception),clear_error(), and_default_publish_handler(message).cloud.py: Addedget_default_home_data()and refactoredset_homes_response(home_data). PatchedMIN_BACKOFF_INTERVALandMAX_BACKOFF_INTERVALinsidepatch_device_manager().simulator.py: Refactored simulator routing to register onpublish_handlerinstead of mutating mock objects.tests:conftest.py: Created shared fixturescloud,fake_device, andpatch_device_managerto be globally accessible.test_device_manager.py: Completely refactored integration tests to use stateful fakes, fixtures, error injection, and dataclass-based home details response overrides.