How to write unit tests of custom components?

I’ve implement a custom component, which I plan to move to its own repo so it can potentially be reused by others.
In the process I wanted to write unit tests; but I could not find any examples outside of the core repo. Any tips?

1 Like

Anybody has any tips?

Checkout:

1 Like

Thanks, I’ve seen that but what I’m looking for is an example of how to use them from another repo.
I guess I could just pip install home-assistant on my development machine and then just import tests, but I was curious to see what others had done.
EDIT except I can’t because setup.py explicitly excludes the tests directory (reasonable).

Hello,
did you find a way to write an unit test for a custom component?
I would like to know which is the best way to write it too.

If you are writing unit tests why not add it to HA as a native component?

Right now I need to figure out how implement the unit test because I’m using my own account for the tests.

I’m facing the same challenge right now. I think it’s going to take lots of reading and sifting through the existing test cases in the HA repository to learn how to write test cases for components.

Sorry to revive such an old conversation, but I am also facing the same challenge and would like to hear any ideas.

3 Likes