/
/
/
1"""Fixtures for testing Music Assistant."""
2
3import logging
4import pathlib
5from collections.abc import AsyncGenerator
6
7import pytest
8
9from music_assistant.mass import MusicAssistant
10
11
12@pytest.fixture(name="caplog")
13def caplog_fixture(caplog: pytest.LogCaptureFixture) -> pytest.LogCaptureFixture:
14 """Set log level to debug for tests using the caplog fixture."""
15 caplog.set_level(logging.DEBUG)
16 return caplog
17
18
19@pytest.fixture
20async def mass(tmp_path: pathlib.Path) -> AsyncGenerator[MusicAssistant, None]:
21 """Start a Music Assistant in test mode.
22
23 :param tmp_path: Temporary directory for test data.
24 """
25 storage_path = tmp_path / "data"
26 cache_path = tmp_path / "cache"
27 storage_path.mkdir(parents=True)
28 cache_path.mkdir(parents=True)
29
30 logging.getLogger("aiosqlite").level = logging.INFO
31
32 mass_instance = MusicAssistant(str(storage_path), str(cache_path))
33
34 # TODO: Configure a random port to avoid conflicts when MA is already running
35 # The conftest was modified in PR #2738 to add port configuration but it doesn't
36 # work correctly - the settings.json file is created but the config isn't respected.
37 # For now, tests that use the `mass` fixture will fail if MA is running on port 8095.
38
39 await mass_instance.start()
40
41 try:
42 yield mass_instance
43 finally:
44 await mass_instance.stop()
45