From 7fe332ad951da25f17da1a6fd5b6ae64a16d613a Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 16 Jan 2026 09:40:07 +0100 Subject: [PATCH] Small fix for 3.14 setup --- changedetectionio/tests/conftest.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/changedetectionio/tests/conftest.py b/changedetectionio/tests/conftest.py index 6da101c46..8972ba8ed 100644 --- a/changedetectionio/tests/conftest.py +++ b/changedetectionio/tests/conftest.py @@ -2,6 +2,7 @@ import psutil import time from threading import Thread +import multiprocessing import pytest import arrow @@ -191,6 +192,34 @@ def cleanup(datastore_path): if os.path.isfile(f): os.unlink(f) +def pytest_configure(config): + """Configure pytest environment before tests run. + + CRITICAL: Set multiprocessing start method to 'fork' for Python 3.14+ compatibility. + + Python 3.14 changed the default start method from 'fork' to 'forkserver' on Linux. + The forkserver method requires all objects to be picklable, but pytest-flask's + LiveServer uses nested functions that can't be pickled. + + Setting 'fork' explicitly: + - Maintains compatibility with Python 3.10-3.13 (where 'fork' was already default) + - Fixes Python 3.14 pickling errors + - Only affects Unix-like systems (Windows uses 'spawn' regardless) + + See: https://github.com/python/cpython/issues/126831 + See: https://docs.python.org/3/whatsnew/3.14.html + """ + # Only set if not already set (respects existing configuration) + if multiprocessing.get_start_method(allow_none=True) is None: + try: + # 'fork' is available on Unix-like systems (Linux, macOS) + # On Windows, this will have no effect as 'spawn' is the only option + multiprocessing.set_start_method('fork', force=False) + logger.debug("Set multiprocessing start method to 'fork' for Python 3.14+ compatibility") + except (ValueError, RuntimeError): + # Already set, not available on this platform, or context already created + pass + def pytest_addoption(parser): """Add custom command-line options for pytest.