Skip to content

Commit 97ce5e0

Browse files
committed
fix: move multiprocessing_start_method_fork fixture to shared conftest
On Python 3.14, the default multiprocessing start method changed from fork to forkserver (python/cpython#132898), which requires all Process arguments to be picklable. The unprivileged_client Kubernetes client object contains thread locks and closures that cannot be pickled, causing _pickle.PicklingError in test_successful_concurrent_uploads. Move the multiprocessing_start_method_fork fixture from tests/chaos/conftest.py to tests/conftest.py so it can be reused across test directories, and apply it to the affected upload test. Changes: - Move fixture to tests/conftest.py (shared across all test dirs) - Remove duplicate from tests/chaos/conftest.py - Add @pytest.mark.usefixtures("multiprocessing_start_method_fork") to test_successful_concurrent_uploads in test_upload.py - Existing chaos consumers (test_standard, test_snapshot, test_migration) resolve the fixture from the parent conftest Signed-off-by: Jathavedhan M <jathavedhan.m@ibm.com>
1 parent bd1c0e4 commit 97ce5e0

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

tests/chaos/conftest.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,3 @@ def deleted_pod_by_name_prefix(admin_client, cnv_pod_deletion_test_matrix__class
406406
namespace=pod_deletion_config["namespace_name"],
407407
pod_prefix=pod_deletion_config["pod_prefix"],
408408
)
409-
410-
411-
@pytest.fixture(scope="module")
412-
def multiprocessing_start_method_fork():
413-
# Use fork context to avoid pickling issues with nested functions
414-
# https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process
415-
# https://github.com/python/cpython/issues/132898
416-
original_start_method = multiprocessing.get_start_method()
417-
multiprocessing.set_start_method("fork", force=True)
418-
yield
419-
multiprocessing.set_start_method(original_start_method, force=True)

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import copy
66
import logging
7+
import multiprocessing
78
import os
89
import os.path
910
import re
@@ -227,6 +228,22 @@
227228
AUDIT_LOG_PATTERN = re.compile(r"audit-(\d{4}-\d{2}-\d{2})T(\d{2})-(\d{2})-(\d{2}\.\d{3})\.log")
228229

229230

231+
@pytest.fixture(scope="module")
232+
def multiprocessing_start_method_fork():
233+
"""Temporarily set multiprocessing start method to ``fork``.
234+
235+
Side effects:
236+
Changes the process-global multiprocessing start method to ``fork``
237+
for the module lifetime, then restores the previous method on teardown.
238+
"""
239+
# https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process
240+
# https://github.com/python/cpython/issues/132898
241+
original_start_method = multiprocessing.get_start_method()
242+
multiprocessing.set_start_method("fork", force=True)
243+
yield
244+
multiprocessing.set_start_method(original_start_method, force=True)
245+
246+
230247
@pytest.fixture(scope="session")
231248
def junitxml_polarion(record_testsuite_property):
232249
"""

tests/storage/cdi_upload/test_upload.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ def _upload_image(dv_name, namespace, storage_class, local_name, client):
284284
@pytest.mark.sno
285285
@pytest.mark.s390x
286286
@pytest.mark.polarion("CNV-2015")
287+
@pytest.mark.usefixtures("multiprocessing_start_method_fork")
287288
@pytest.mark.parametrize(
288289
"upload_file_path",
289290
[

0 commit comments

Comments
 (0)