Test your change
This page helps you show that your change works before you open a pull request, and lets you try someone else’s change.
Run the tests
Section titled “Run the tests”With .venv active, from the root of the repository:
pytest # all testspytest tests/providers/airplay # one folderpytest tests/core/test_diagnostics.py # one filepytest -n auto --dist loadfile # in parallel, the tests of one file in one workerA test that runs longer than 120 seconds fails. When a pull request changes only providers, CI runs only their tests; any other code change runs them all.
Where a test goes
Section titled “Where a test goes”| Change in | Test in |
|---|---|
music_assistant/providers/<domain>/ |
tests/providers/<domain>/ |
music_assistant/controllers/<name>/ |
tests/controllers/<name>/ |
music_assistant/helpers/ |
tests/helpers/ |
mass.py, provider loading, the diagnostics |
tests/core/ |
| A flow across controllers with the fake providers | tests/integration/ |
A test file directly in tests/providers/ or tests/controllers/ fails the check_test_layout hook: CI finds the tests of a provider by its folder.
The mass fixtures
Section titled “The mass fixtures”tests/conftest.py gives every test a few ready servers on a temporary folder:
mass: a fully started server;mass_minimal: only the event loop and the config controller;music_mass: only the library database, fresh.
The full server comes from full_mass_context in music_assistant/testing.py. It listens on the loopback address only, announces nothing on the network, sets up no player providers by default and starts no library sync. A provider in its own repository gets the same server from that module, see Building a provider.
Checks
Section titled “Checks”Run pre-commit run --all-files before you push. The hooks, also installed by scripts/setup.sh to run on each commit, run ruff, mypy and codespell, and the project’s own checks in scripts/: no blocking calls in async code, public methods above private ones, the datetime helpers instead of datetime.now(), texts in strings.json, valid manifests and the test layout. Some hooks rewrite files, such as requirements_all.txt and translations/en.json: commit those changes too. .pre-commit-config.yaml lists every hook.
Player scenario tests
Section titled “Player scenario tests”tests/scenarios/ describes what a client sees when players are found, lost, grouped, merged or removed. Each test drives a real server with fake player providers and a virtual clock, through the calls that providers and clients use. Every scenario has an entry in plain words in the players controller’s SCENARIOS.md, and a test fails when the two disagree. The scenarios README explains the harness.
Performance benchmark
Section titled “Performance benchmark”scripts/perf/run_benchmark.py boots a server without network access, runs a fixed set of scenarios (startup, library sync, API calls, streaming, memory) and writes a JSON report.
.venv/bin/python scripts/perf/run_benchmark.py --quick --save-baseline # before your change.venv/bin/python scripts/perf/run_benchmark.py --quick --compare # after it--compare exits non-zero on a regression. Numbers only compare on the same machine, and the benchmark does not run in CI. The benchmark README explains every metric.
Test on a real device
Section titled “Test on a real device”The tests fake every speaker. A change to a player provider, or to other code that talks to a device, also needs a test on the real device. Run it against a server with a data folder of its own and say in the pull request which device you tested on. Until you do, such a change needs a maintainer’s approval, not only the review bot’s.
A change to playback, a queue or a player can also go through the end-to-end test lab. It plays your change on virtual players, which adds to the test on your device but does not replace it.
End-to-end test lab
Section titled “End-to-end test lab”The end-to-end test lab runs a pull request or a branch of the server repository on a fresh server with virtual AirPlay, DLNA, Squeezelite, Snapcast, MPD and Sendspin players, captures the audio each player received and reports pass or fail. It hears what a test with fake players cannot, such as a gap between the tracks of an album, a pause that does not hold, grouped players that play out of sync or a crossfade that does not overlap.
lab run --ref pr/123 --areas queue # the core and queue checkslab run --ref pr/123 --providers airplay # the core checks and the journey of one player providerlab summary <run id> # per area: the check that failed and its related issuesThe PR gate guide maps the files you changed to the runs they need and lists what each area checks. The lab only reaches branches of the server repository: for a branch on your fork, open a draft pull request and run --ref pr/<number>. Put the result in the pull request.
You build the lab yourself, as one of these, both described in its SETUP.md:
- a Linux VM on a network segment of its own, which can also drive real speakers on a test bench. It needs a hypervisor, and a router that keeps that segment out of your home network;
- a Linux VM on your own machine, with NAT networking and virtual players only. This variant has had less use: its Lima recipe is untested on Apple silicon.
Built as SETUP.md describes, no lab player can reach a speaker in your home.
Try a branch or pull request without a development setup
Section titled “Try a branch or pull request without a development setup”The development image ghcr.io/music-assistant/server:dev is the nightly server plus the tools to run other code. Three environment variables say what to run; an empty one is not used:
SERVER_REPO: a branch (dev), a pull request (pr-123), a full commit hash, or a fork asowner/repo(its default branch) orowner/repo@ref. A name with a slash is a branch when the server repository has one by that name, else a fork;FRONTEND_REPO: the web interface to build, in the same forms;PROVIDER_REPO: a repository with providers, asowner/repo,owner/repo@reforowner/repo@pr-12.
docker run --rm --network host -v ma-dev-data:/data \ -e SERVER_REPO=pr-123 \ ghcr.io/music-assistant/server:devWith Docker Compose:
services: music-assistant-dev: image: ghcr.io/music-assistant/server:dev network_mode: host volumes: - ma-dev-data:/data environment: SERVER_REPO: pr-123
volumes: ma-dev-data:Arguments after the image name go to the server, such as --log-level debug. A restart fetches and installs the named code again; pull the image again for a newer nightly. In Home Assistant, the Music Assistant DEV SERVER app runs the same image, with the options server_repo, frontend_repo and provider_repo. It appears in the app store when Advanced mode is on in your user profile; see its README. Both run whatever code you name, so use them to test, not as your daily server.
Run a provider from another folder
Section titled “Run a provider from another folder”A provider in a repository of its own runs from where it is, in the dev mode of the server:
PYTHONDEVMODE=1 python -m music_assistant --dev-providers-dir /path/to/my_providers- The folder holds provider folders named after their
domain, a folder namedprovider, orproviders/<domain>. - Pass the option more than once for several folders; on the same
domain, the first folder wins. - A
domainthe server already has is refused, and a provider whose requirements clash with the server’s is not loaded. - A change to the code takes effect after a restart.
Music Assistant is a project of the Open Home Foundation.