Skip to content

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.

With .venv active, from the root of the repository:

Terminal window
pytest # all tests
pytest tests/providers/airplay # one folder
pytest tests/core/test_diagnostics.py # one file
pytest -n auto --dist loadfile # in parallel, the tests of one file in one worker

A 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.

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.

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.

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.

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.

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.

Terminal window
.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.

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.

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.

Terminal window
lab run --ref pr/123 --areas queue # the core and queue checks
lab run --ref pr/123 --providers airplay # the core checks and the journey of one player provider
lab summary <run id> # per area: the check that failed and its related issues

The 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 as owner/repo (its default branch) or owner/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, as owner/repo, owner/repo@ref or owner/repo@pr-12.
Terminal window
docker run --rm --network host -v ma-dev-data:/data \
-e SERVER_REPO=pr-123 \
ghcr.io/music-assistant/server:dev

With 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.

A provider in a repository of its own runs from where it is, in the dev mode of the server:

Terminal window
PYTHONDEVMODE=1 python -m music_assistant --dev-providers-dir /path/to/my_providers
  • The folder holds provider folders named after their domain, a folder named provider, or providers/<domain>.
  • Pass the option more than once for several folders; on the same domain, the first folder wins.
  • A domain the 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.