From b18d50510614aea9f5e61e06d26382e4a004a36a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 3 Dec 2025 20:43:53 +0100 Subject: [PATCH] Fix tests (for now) --- tests/conftest.py | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 32d4a62b..1b2d0edc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,29 +1,14 @@ """Fixtures for testing Music Assistant.""" -import json import logging import pathlib -import socket from collections.abc import AsyncGenerator -import aiofiles import pytest from music_assistant.mass import MusicAssistant -def get_free_port() -> int: - """Get a free port number. - - :return: Available port number. - """ - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - s.bind(("", 0)) - s.listen(1) - port: int = s.getsockname()[1] - return port - - @pytest.fixture(name="caplog") def caplog_fixture(caplog: pytest.LogCaptureFixture) -> pytest.LogCaptureFixture: """Set log level to debug for tests using the caplog fixture.""" @@ -33,7 +18,7 @@ def caplog_fixture(caplog: pytest.LogCaptureFixture) -> pytest.LogCaptureFixture @pytest.fixture async def mass(tmp_path: pathlib.Path) -> AsyncGenerator[MusicAssistant, None]: - """Start a Music Assistant in test mode with a random available port. + """Start a Music Assistant in test mode. :param tmp_path: Temporary directory for test data. """ @@ -44,23 +29,13 @@ async def mass(tmp_path: pathlib.Path) -> AsyncGenerator[MusicAssistant, None]: logging.getLogger("aiosqlite").level = logging.INFO - # Get a free port and pre-configure it before starting - test_port = get_free_port() - - # Create a minimal config file with the test port - config_file = storage_path / "settings.json" - config_data = { - "core": { - "webserver": { - "bind_port": test_port, - } - } - } - async with aiofiles.open(config_file, "w") as f: - await f.write(json.dumps(config_data)) - mass_instance = MusicAssistant(str(storage_path), str(cache_path)) + # TODO: Configure a random port to avoid conflicts when MA is already running + # The conftest was modified in PR #2738 to add port configuration but it doesn't + # work correctly - the settings.json file is created but the config isn't respected. + # For now, tests that use the `mass` fixture will fail if MA is running on port 8095. + await mass_instance.start() try: -- 2.34.1