Testing a MQTT library against a docker-compose with home-assistant and mosquitto

Maybe this is a XY problem, so I’ll start for my goal: testing a library/application that uses MQTT discovery for exposing components to Home Assistant.

The application is working, but I want to automate tests. My idea was to have a docker-compose with home-assitant and mosquitto and set them up with pytest. With that, proceed to do my tests and validate that everything is working and nothing is being broken.

However, the default home-assistant container starts without users and asks for doing a onboarding process. I don’t need onboarding, I only want the API in order to test the components. I cannot use a token for API access until there is a user, and I cannot create a user without a token. I want to do it automatically and fast. I thought about storing/retrieving/modifying the .storage folder, but that seems hackish and is not an intended way of doing things AFAICT. I found some devcontainers but they do not seem to be appropriate, but maybe I’m mistaken.

Has somebody out there done something similar? Is there something I overlooked?

Hey abarcelo,

I know that your post is over a year old. But did you find a solution?
I’m facing the same problem.

I also want to do integration tests with a “real” HASS and MQTT Broker.


No. The library does not have automated tests for now :slightly_frowning_face: