diff --git a/tests/firedrake/conftest.py b/tests/firedrake/conftest.py index 695239b685..1fd9344dd6 100644 --- a/tests/firedrake/conftest.py +++ b/tests/firedrake/conftest.py @@ -9,6 +9,7 @@ os.environ["FIREDRAKE_DISABLE_OPTIONS_LEFT"] = "1" import pytest +from mpi4py import MPI from petsctools import get_external_packages from pyadjoint.tape import ( annotate_tape, get_working_tape, set_working_tape, @@ -256,3 +257,10 @@ def __exit__(self, exc_type, exc_val, traceback): def petsc_raises(): # This function is needed because pytest does not support classes as fixtures. return _petsc_raises + + +@pytest.fixture +def garbage_cleanup(): + """Fixture that runs the parallel garbage collector.""" + yield + PETSc.garbage_cleanup(MPI.COMM_WORLD) diff --git a/tests/firedrake/output/test_io_function.py b/tests/firedrake/output/test_io_function.py index 0ea6812428..9169b7919a 100644 --- a/tests/firedrake/output/test_io_function.py +++ b/tests/firedrake/output/test_io_function.py @@ -16,6 +16,11 @@ func_name = "f" +@pytest.fixture(autouse=True) +def autouse_garbage_cleanup(garbage_cleanup): + pass + + def _initialise_function(f, _f, method): if method == "project": getattr(f, method)(_f, solver_parameters={"ksp_type": "cg", "pc_type": "sor", "ksp_rtol": 1.e-16}) diff --git a/tests/firedrake/regression/test_covariance_operator.py b/tests/firedrake/regression/test_covariance_operator.py index 4a5ab20257..3fce2c7df3 100644 --- a/tests/firedrake/regression/test_covariance_operator.py +++ b/tests/firedrake/regression/test_covariance_operator.py @@ -39,7 +39,7 @@ def rng(): @pytest.mark.parametrize("family", ("CG", "DG")) @pytest.mark.parametrize("mesh_type", ("interval", "square")) @pytest.mark.parametrize("backend_type", (PyOP2NoiseBackend, PetscNoiseBackend), ids=("pyop2", "petsc")) -def test_white_noise(family, degree, mesh_type, dim, backend_type, rng): +def test_white_noise(family, degree, mesh_type, dim, backend_type, rng, garbage_cleanup): """Test that white noise generator converges to a mass matrix covariance. """