Testing setup only — no production code changes.
Problem
tests/unit/ cannot run under pytest-xdist. tox.ini:65 therefore pins it serial by
default (-n {env:UNIT_XDIST_N:0}), and unit is the largest suite in the repo (6031
items), so this is the single biggest serial block in a full run.
Setting UNIT_XDIST_N=16 produces:
16 workers [6031 items]
INTERNALERROR> execnet.gateway_base.DumpError: can't serialize <class 'unittest.mock.MagicMock'>
INTERNALERROR> AssertionError: ('tests/unit/test_tenant_name_sync.py::test_context_processor_handles_missing_tenant', <WorkerController gw13>)
unit: exit 3 (112.65 seconds)
test_context_processor_handles_missing_tenant produces a failure payload containing a
MagicMock. execnet (xdist's wire protocol) cannot pickle it, the worker raises an
internal error, and that kills the whole session.
Why this is worse than a plain failure
The run reports 6031 items collected, 3183 reported — roughly 2,800 unit tests
silently never reported — while the JSON summary reads passed: 3152, failed: 0.
A green-looking report over a third of a missing suite. Only the tox exit code (3) and
the collected-vs-reported delta reveal it.
What's needed
- Make the test's failure payload serializable (don't let a
MagicMock reach the
assertion/repr that crosses the worker boundary).
- Sweep
tests/unit/ for the same shape — anything that can put a mock into a failure
repr is a latent instance of this.
- Then flip the
UNIT_XDIST_N default off serial and confirm collected == reported.
Acceptance
UNIT_XDIST_N=16 (and auto) completes with no INTERNALERROR.
- Collected count equals reported count in
unit.json.
- Suite result is identical serial vs parallel.
Notes
Self-contained and independent of #2007/#2008/#2009/#2010 — this one can land on
its own and immediately parallelizes the largest suite.
Testing setup only — no production code changes.
Problem
tests/unit/cannot run underpytest-xdist.tox.ini:65therefore pins it serial bydefault (
-n {env:UNIT_XDIST_N:0}), and unit is the largest suite in the repo (6031items), so this is the single biggest serial block in a full run.
Setting
UNIT_XDIST_N=16produces:test_context_processor_handles_missing_tenantproduces a failure payload containing aMagicMock. execnet (xdist's wire protocol) cannot pickle it, the worker raises aninternal error, and that kills the whole session.
Why this is worse than a plain failure
The run reports 6031 items collected, 3183 reported — roughly 2,800 unit tests
silently never reported — while the JSON summary reads
passed: 3152, failed: 0.A green-looking report over a third of a missing suite. Only the tox exit code (3) and
the collected-vs-reported delta reveal it.
What's needed
MagicMockreach theassertion/repr that crosses the worker boundary).
tests/unit/for the same shape — anything that can put a mock into a failurerepr is a latent instance of this.
UNIT_XDIST_Ndefault off serial and confirm collected == reported.Acceptance
UNIT_XDIST_N=16(andauto) completes with noINTERNALERROR.unit.json.Notes
Self-contained and independent of #2007/#2008/#2009/#2010 — this one can land on
its own and immediately parallelizes the largest suite.