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.
This commit is contained in:
Goffi 2026-04-09 21:37:07 +02:00
commit 72d7868eb5

View file

@ -16,7 +16,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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()