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:
parent
0cfeea8203
commit
72d7868eb5
1 changed files with 11 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue