Repository navigation
Description
Overview
PyAutoFit#1657 (community fix, discussion https://github.com/orgs/PyAutoLabs/discussions/27) changed fork_context() so that on macOS/Windows it returns the multiprocessing module instead of calling multiprocessing.get_context() with no argument — that no-arg call ran at import time and locked the default start method, so a later set_start_method(...) raised "context has already been set". Ubuntu CI never reaches the darwin/win32 branch, so the fix has no regression protection. This task adds tests that exercise that branch on Linux CI by monkeypatching sys.platform.
Plan
- Add darwin-path tests to
test_autofit/non_linear/test_fork_context.py:fork_context()returns themultiprocessingmodule and exposesProcess,Queue,Pool. - Spy on
multiprocessing.get_contexton that path and assert it is never called with no argument. - Keep the existing Linux
get_context("fork")assertion. - Witness: revert the final line of
context.pytoreturn multiprocessing.get_context()locally — the new test fails; restore — it passes.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: feature/fork-context-darwin-test
Implementation Steps
- In
test_autofit/non_linear/test_fork_context.py, add a test that usesmonkeypatch.setattr(sys, "platform", "darwin")and assertsfork_context() is multiprocessingand that it hasProcess,Queue,Pool. - Add a test that, on the darwin path, replaces
multiprocessing.get_contextwith a recording spy (monkeypatch) and asserts no call was made with no argument (the pre-fix: do not fix the multiprocessing start method at import time on macOS #1657 import-time call). - Keep
test_fork_context_is_fork(Linuxget_context("fork")) unchanged; monkeypatch restores all state so conftest'sforksetting is unaffected. - Witness: temporarily revert
autofit/non_linear/parallel/context.pyfinal line toreturn multiprocessing.get_context(); new tests fail; restore; they pass. - Run
python -m pytest test_autofit/non_linear/test_fork_context.py -qand the fulltest_autofitsuite.
Key Files
autofit/non_linear/parallel/context.py—fork_context()(code under test, unchanged)test_autofit/non_linear/test_fork_context.py— new tests
Links: PyAutoFit#1657, https://github.com/orgs/PyAutoLabs/discussions/27
Original Prompt
Click to expand starting prompt
PyAutoFit: add a regression test for fork_context() not fixing the multiprocessing start…
Type: bug
Target: PyAutoFit
Repos:
- PyAutoFit
Difficulty: small
Autonomy: safe
Priority: high
Memory: wiki/lensing/sources/dark-matter-substructure.md; wiki/galaxies/sources/massive-ellipticals.md; wiki/galaxies/sources/cosmos-survey.md
Status: formalised
Consequence: glance
Witness: a new test under test_autofit that monkeypatches sys.platform="darwin" and reloads parallel.context asserts multiprocessing.context._default_context._actual_context is None; it fails on the pre-fix: do not fix the multiprocessing start method at import time on macOS #1657 code (revert the context.py hunk locally) and passes on main
Review-minutes: 3
Unattended: ready
PyAutoFit: add a regression test for fork_context() not fixing the multiprocessing start method at import on darwin/win32.
Community PR PyAutoFit#1657 (@samlange04, discussion https://github.com/orgs/PyAutoLabs/discussions/27, merged 2026-10-07) changed autofit/non_linear/parallel/context.py so that on non-Linux platforms fork_context() returns the multiprocessing module instead of multiprocessing.get_context(), because the no-argument get_context() call at import time (parallel/process.py:47 builds class Process(fork_context().Process)) locked the interpreter's default start method and made any later set_start_method("spawn") raise "context has already been set". The PR has no test and Ubuntu CI cannot reach the darwin/win32 branch, so the fix is unprotected against regression.
Fix: add a test (next to test_fork_context.py) that monkeypatches sys.platform = "darwin", reloads autofit.non_linear.parallel.context and process, and asserts multiprocessing.context._default_context._actual_context is None afterwards (i.e. importing did not fix the start method), and that the returned object exposes .Process, .Queue and .Pool. Keep the existing Linux assertion (get_context("fork")) intact and restore the module state after the test so conftest's fork setting is unaffected.
Activity
Jammy2211 commentedon Oct 7, 2026
Library PR created: #1662 (test-only; 4 new darwin/win32 tests, witness red on the reverted #1657 hunk, full test_autofit 2965 passed / 2 skipped). No workspace impact. Awaiting human /prm.
Jammy2211 commentedon Oct 7, 2026
Shipped: merged in #1662 as 1e58fb1 (pending release). Closing.
test: cover fork_context() darwin/win32 branch (no start-method fix a…