Fix tests (for now)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 3 Dec 2025 19:43:53 +0000 (20:43 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 3 Dec 2025 19:43:53 +0000 (20:43 +0100)
tests/conftest.py

index 32d4a62b67a3490144d21f101a22cf9e12c6fdde..1b2d0edc0b30be218cd8cc915d7a65ff4d8699b4 100644 (file)
@@ -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: