From cdd8508bc94eb4399857546ebd1b427241829dc2 Mon Sep 17 00:00:00 2001 From: "Commentator2.0" Date: Mon, 22 Dec 2025 20:34:11 +0100 Subject: [PATCH] tests/functional2: Provide a shortcut to clear a store Change-Id: Ic28fb8a81ef95a1b83fa8099f5337e89f630f8e1 --- tests/functional2/testlib/fixtures/nix.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional2/testlib/fixtures/nix.py b/tests/functional2/testlib/fixtures/nix.py index c12e56a36..d01105dbd 100644 --- a/tests/functional2/testlib/fixtures/nix.py +++ b/tests/functional2/testlib/fixtures/nix.py @@ -286,6 +286,22 @@ class Nix: res = self.nix(["hash", "path", actual_path, *args], flake=True).run().ok() return res.stdout_plain + def clear_store(self): + """ + Clears the test-owned store (and state) and resets them to an empty state + """ + nix_store_dir = self.env.dirs.nix_store_dir + state_dir = self.env.dirs.nix_state_dir + + # Make store writable + Command(["chmod", "-R", "+w", nix_store_dir], self.env).run().ok() + shutil.rmtree(nix_store_dir) + shutil.rmtree(state_dir) + + # Re-create the directories + nix_store_dir.mkdir() + state_dir.mkdir() + _fully_sandboxed = ( sys.platform == "linux"