Skip to content

Make test_tokamak_parameter spawn-safe#560

Open
samc24 wants to merge 1 commit into
devfrom
sameerc/fix-test-decorator-spawn
Open

Make test_tokamak_parameter spawn-safe#560
samc24 wants to merge 1 commit into
devfrom
sameerc/fix-test-decorator-spawn

Conversation

@samc24
Copy link
Copy Markdown
Collaborator

@samc24 samc24 commented May 25, 2026

Summary

Fix tests/test_decorator.py::test_tokamak_parameter[None] hanging indefinitely under multiprocessing's spawn start method (macOS default; Linux default in Python 3.14+).

Root cause

The test defined my_physics_method as a function-local global. Under fork (current Linux default), spawned workers inherit the parent process's module globals, so the attribute exists. Under spawn/forkserver, workers
re-import the test module from scratch — my_physics_method doesn't exist yet because the test function hasn't run there — so unpickling the function reference fails:

AttributeError: Can't get attribute 'my_physics_method' on <module 'test_decorator'>

The worker dies silently; the parent pool waits forever on queue.get().

Fix

Move the two physics-method variants to module scope and parametrize over the method rather than the tokamak argument. Module-scope functions exist at import time, so spawned workers can find them by reference.

No production code changes.

Why this matters now

Python 3.14 makes forkserver the default POSIX start method. The current pattern works on Linux CI today only because it forks; that breaks when the project moves to 3.14. This fix preempts the Linux-CI failure as well as fixing the
existing macOS hang, and unblocks the macOS test matrix being introduced on glt/macbook.

Behavior change

Test IDs change:

  • test_tokamak_parameter[None]test_tokamak_parameter[tokamak=None]
  • test_tokamak_parameter[Tokamak.<X>]test_tokamak_parameter[tokamak=resolved]

Test plan

  • pytest tests/test_decorator.py::test_tokamak_parameter — both parametrizations pass in ~16s on macOS (spawn default)
  • make black / ruff / pylint clean on changed file
  • CI: confirm Linux fork path still passes

Signed-off-by: Sameer Chaturvedi <sameerc@mit.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant