Skip to content

Fail tests with uncaught exceptions#33312

Merged
balloob merged 2 commits intohome-assistant:devfrom
ziv1234:test_exceptions
Mar 28, 2020
Merged

Fail tests with uncaught exceptions#33312
balloob merged 2 commits intohome-assistant:devfrom
ziv1234:test_exceptions

Conversation

@ziv1234
Copy link
Copy Markdown
Contributor

@ziv1234 ziv1234 commented Mar 27, 2020

Breaking change

Not a breaking change

Proposed change

Today, if a test has an exception that gets uncaught in the event loop, the test still succeeds. However, it is a better programming practice to have exceptions caught, as it is not good to completely ignore it.
Most tests pass today and I added a file with the ignored tests.
This will immediately force all new tests to either not have uncaught exceptions or be added to the ignored tests (which we should not permit too easily).
Over time, I will create PRs to fix the tests. In a few random ones I picked, it is usually a very minor fix. The file can definitely be reduced significantly and potentially eliminated, which will make the code better and more stable

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation 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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Comment thread tests/conftest.py
Comment on lines +105 to +106
if isinstance(ex, ServiceNotFound):
continue
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we can reduce this by setting up persistent notification, which seems to be causing most errors. But that is for future us, this is already a great improvement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the problem is that it happens for components that don't use persistent notifications directly (like mine, Dynalite...). I plan to take a look at this as part of the exception reduction, but i have a bit less than 200 exceptions today in the file. If i remove this line it becomes 1600.

Copy link
Copy Markdown
Member

@balloob balloob Mar 28, 2020

Choose a reason for hiding this comment

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

We could consider to set persistent_notification up as part of the hass fixture.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right now we ignore all service not found errors, I bet that we're missing some real ones too. But let's keep this for the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i believe that setting it for all the tests will increase the test time significantly. We can add mock service calls for the persistent notifications in the hass fixture and will likely catch the same errors since persistent notifications are always supposed to be set up, right?

@balloob balloob changed the title initial implementation and ignore file Fail tests with uncaught exceptions Mar 28, 2020
Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Awesome! I think our next step will be to create issues for the integrations that have uncaught exceptions and notify code owners.

@balloob
Copy link
Copy Markdown
Member

balloob commented Mar 28, 2020

Done ;)

@lock lock Bot locked and limited conversation to collaborators Apr 2, 2020
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.

3 participants