diff --git a/changes/3977.bugfix.md b/changes/3977.bugfix.md new file mode 100644 index 0000000000..6a8d9b4244 --- /dev/null +++ b/changes/3977.bugfix.md @@ -0,0 +1 @@ +Fix flaky stateful test bookkeeping when `delete_dir` matches string prefixes instead of true directory descendants. Previously a path such as `6/faNT…` could be incorrectly removed when deleting `6/f`. (See [issue #3977](https://github.com/zarr-developers/zarr-python/issues/3977).) diff --git a/src/zarr/testing/stateful.py b/src/zarr/testing/stateful.py index d6c43f4ecc..78f6a9671b 100644 --- a/src/zarr/testing/stateful.py +++ b/src/zarr/testing/stateful.py @@ -306,7 +306,7 @@ def delete_dir(self, data: DataObject) -> None: matches = set() for node in self.all_groups | self.all_arrays: - if node.startswith(path): + if node == path or node.startswith(path + "/"): matches.add(node) self.all_groups = self.all_groups - matches self.all_arrays = self.all_arrays - matches diff --git a/tests/test_store/test_stateful.py b/tests/test_store/test_stateful.py index 82b482d0ff..3232ef5120 100644 --- a/tests/test_store/test_stateful.py +++ b/tests/test_store/test_stateful.py @@ -49,3 +49,5 @@ def mk_test_instance_sync() -> ZarrStoreStateMachine: # But LocalStore, directories can hang around even after a key is delete-d. pytest.skip(reason="Test isn't suitable for LocalStore.") run_state_machine_as_test(mk_test_instance_sync) # type: ignore[no-untyped-call] + +