From 72d7868eb59037257fa653563daa711e718cba86 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 9 Apr 2026 21:37:07 +0200 Subject: [PATCH] tests (unit/conftests): Add a `reset_storage` autouse fixture: Storage can be modified by tests, and it is kept for the whole session, this may have side effect resulting in other tests failing. This fixture avoid this problem by reseting `storage` between each test. --- tests/unit/conftest.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 17224e59..f30a84ae 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from contextlib import contextmanager from unittest.mock import MagicMock, AsyncMock from pytest import fixture from twisted.internet import defer @@ -105,3 +104,14 @@ def client(): client.tor = None client.tor_mode = TorMode.DISABLED return client + + +@fixture(autouse=True) +def reset_storage(host): + """Replace storage with a fresh mock before each test. + + The host and storage fixtures use session scope, which means any assignments to + storage attributes (e.g., storage.method = AsyncMock(...)) persist across tests. This + fixture ensures each test starts with a clean slate. + """ + host.memory.storage = AsyncMock()