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

Convert MQTT Light tests to async #17754

merged 1 commit into from Oct 26, 2018


None yet
3 participants

balloob commented Oct 24, 2018


To migrate restore_state (PR #17270) to use the storage helper instead of history, we need to migrate all tests for components/platforms that use restore state to async or else the pytest fixtures won't work.

As a test to see how difficult it was, I converted the MQTT light tests. It took ~15-20 min because I had to figure out what things to change, but future ones we should be able to do faster. Things to do per test migration:

  • self.mock_publish should be replaced with fixture mock_mqtt
  • All functions need mock_publish fixture, also if they don't use it. This is because the fixture mocks out the whole MQTT component and we do use that.
  • self.hass should be replaced with fixture hass
  • Calls to common.* should be replaced with common.async_
  • all functions need to be moved outside of the class, have parameter self removed and be marked as async.
  • hass.block_till_done -> await hass.async_block_till_done(). Because async_block_till_done blocks 1 less cycle than block_till_done, you might sometimes have to call it twice 🤷‍♂️
  • calls to setup_component need to be replaced with await async_setup_component
  • fire_mqtt_message -> async_fire_mqtt_message


  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@wafflebot wafflebot bot added the in progress label Oct 24, 2018

@balloob balloob merged commit 644c33c into dev Oct 26, 2018

6 checks passed

Hound No violations found. Woof!
WIP ready for review
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed
coverage/coveralls Coverage remained the same at 93.556%

@balloob balloob deleted the light-mqtt-tests branch Oct 26, 2018

@wafflebot wafflebot bot removed the in progress label Oct 26, 2018

@balloob balloob referenced this pull request Nov 9, 2018


0.82 #18335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment