Skip to content

Fix MPI test teardown failure caused by unpicklable pytest tmpdir fixture#655

Draft
Copilot wants to merge 1 commit into
masterfrom
copilot/fix-user-cpu-tests-linux
Draft

Fix MPI test teardown failure caused by unpicklable pytest tmpdir fixture#655
Copilot wants to merge 1 commit into
masterfrom
copilot/fix-user-cpu-tests-linux

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

test_loggingMPI was failing with AttributeError: Can't pickle local object '_BaseExitStack._create_cb_wrapper.<locals>._exit_wrapper' in all MPI ranks.

Root cause

Using pytest's tmpdir fixture triggers TempPathFactory.getbasetemp(), which registers callbacks on an internal ExitStack. In pytest ≥8.1, these callbacks are wrapped in _create_cb_wrapper.<locals>._exit_wrapper — a local function that cannot be pickled. pytest-isolate-mpi attempts to pickle all session-scoped fixtures (including tmp_path_factory) during teardown via _cache_fixture_result, causing the teardown to error.

Fix

Replace the tmpdir fixture dependency in test_loggingMPI with tempfile.mkdtemp(), avoiding tmp_path_factory entirely. Rank 0 creates the directory, broadcasts the path string to all ranks, and cleans up after the test.

@pytest.mark.mpi4py
@pytest.mark.mpi(ranks=[1, 4])
def test_loggingMPI(comm, mpi_ranks):
    # `mpi_ranks` is a pytest fixture required by pytest-isolate-mpi. Do not remove.
    import tempfile, shutil

    tmpdir = tempfile.mkdtemp() if comm.rank == 0 else None
    tmpdir = comm.bcast(tmpdir, root=0)
    try:
        test_logging(tmpdir, False, False)
    finally:
        if comm.rank == 0:
            shutil.rmtree(tmpdir, ignore_errors=True)

Copilot AI changed the title [WIP] Fix failing GitHub Actions job user_cpu_tests_linux (mpi4py, 3.10) Fix MPI test teardown failure caused by unpicklable pytest tmpdir fixture Jun 22, 2026
Copilot AI requested a review from pancetta June 22, 2026 07:46
@github-actions

Copy link
Copy Markdown

Coverage report

This PR does not seem to contain any modification to coverable code.

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.

2 participants