diff --git a/tests/test_utils_pvpreload.py b/tests/test_utils_pvpreload.py index a34a889b1..7711a4e5c 100644 --- a/tests/test_utils_pvpreload.py +++ b/tests/test_utils_pvpreload.py @@ -142,6 +142,26 @@ def test_preload_old_file(tmp_path, caplog): # Vérifie que le PV n’a pas été créé (pas dans le cache) assert not is_pv_in_cache(pvname) +def test_preload_fichier_corrompu(tmp_path, caplog): + configure_logzero_for_pytest(caplog) + + f = tmp_path / "corrupt.pkl" + + # Écrit un fichier non valide (pas du pickle) + with open(f, "w") as fcorrupt: + fcorrupt.write("not a pickle at all") + + # Patch le chemin du fichier dans preload + with pytest.MonkeyPatch().context() as mp: + mp.setattr("slic.utils.pvpreload.fn", f) + + with caplog.at_level("WARNING"): + preload() + + logs = "\n".join(caplog.messages) + assert "PV preload file not loaded due to: UnpicklingError:" in logs + + # offload() def test_offload(tmp_path, caplog):