Python "MemoryError" During Tests in CI
A test run exhausted the runner’s memory and Python raised MemoryError (or the process was OOM-killed). Either a single test allocates too much, or memory accumulates across the suite.
What this error means
Tests fail with MemoryError, or the run is killed abruptly with no traceback (the OOM killer). It often appears only in CI, where the runner has less RAM than a developer machine.
tests/test_pipeline.py::test_large_join
result = pd.concat(frames) # accumulates every frame
MemoryErrorCommon causes
A single test allocates too much
Loading a large dataset, building a huge structure, or concatenating many frames in one test exceeds the runner’s memory.
Memory accumulates across tests
A module-scoped fixture or a global cache that grows per test leaks memory through the suite until it runs out.
How to fix it
Shrink fixtures and free memory
Use small representative fixtures and release large objects between tests.
@pytest.fixture
def frame():
df = make_small_frame() # not the full production dataset
yield df
del df # release before the next testIsolate or right-size the run
- Run heavy tests in a separate, higher-memory job if the size is genuine.
- Use function-scoped fixtures so large objects are not retained.
- Reduce
-n(xdist workers) - each worker holds its own memory.
How to prevent it
- Keep test fixtures small and representative, not production-scale.
- Free large objects between tests; prefer function-scoped fixtures.
- Right-size the runner (or worker count) for genuinely heavy suites.